select *,(SELECT C_NO FROM FRONTDB.CP_CATEGORY_GOODS as b WHERE b.C_NO = '68' AND b.GOODS_NO = a.P_NO GROUP BY b.C_NO ORDER BY b.C_NO DESC limit 1) AS C_NO from FRONTDB.CP_PKG as a where a.P_TYPE=2 and (a.P_USEFLAG='Y' or ( a.P_STIME <= '1607169503' AND a.P_ETIME >= '1607169503' AND a.P_USEFLAG='N' )) and a.CPN_CO_CD='1025' AND ((a.P_OPT is NULL OR a.P_OPT = 0) OR ((a.P_OPT = 1 AND

IN (1631,1116,1292,1320,1625,1446,1697,1643,2032,1402,1403,1405,1406,1296,1404,1025,1132, 2507, 2534, 2535, 2241, 2698, 2758)) OR (a.P_OPT = 2 AND
NOT IN (1631,1116,1292,1320,1625,1446,1697,1643,2032,1402,1403,1405,1406,1296,1404,1025,1132, 2507, 2534, 2535, 2241, 2698, 2758)))) AND P_NO IN(SELECT GOODS_NO FROM FRONTDB.CP_CATEGORY_GOODS WHERE C_NO='188' AND CG_KIND='pkg') And a.P_NO NOT In('2872','2875','2876','2879','2880','2883','2885','2886','2889','2891','2892','2895','2898','2900','2901','2904','2905','2908','2909','1742','2400','2402','1769','2403','1683','1680','2404','2230','1988','2809','2816','2808','2818','2817','2807','2823','2821','2806','2825','2813','2827','2826','2810','2822','2814','2815','2824','2819','2820','2812','2811','2703','2701','2728','2721','2743','2739','2733','2723','2735','2730','2746','2737','2747','2699','2725','2732','2750','553','2911','2913','2915','2917','2919','2921','2923','2925','2927','2929','2931','2933','2935','2937','2939','2941','2943','2945','2947','2949','2951','2236','1996','2453','1992','2742','1924','2681','2769','2235','2452','1994','2226','1350','1836','1750','1494','2497','1361','1491','1898','1494') order by a.P_ORD

1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '