SELECT EP.*, COUNT(AU.EPID) EPCOUNT FROM EP_CATAGORY EP LEFT JOIN EP_AUTHEN_INST AU ON EP.CATID=AU.CATID AND AU.USERID='1' GROUP BY EP.CATID HAVING EP.USERID='1' OR (EP.USERID=0 AND EP.CATTYPEID=1 AND EP.CATUSERTYPEID='2') ORDER BY EP.REORDER, EP.CATID
นู๋ใช้ oracle แล้วที่นี้มันบอกว่าไม่มีเอ็กซ์เพรสชัน GROUP BY
SELECT EP.CATID, COUNT(AU.EPID) EPCOUNT FROM EP_CATAGORY EP LEFT JOIN EP_AUTHEN_INST AU ON EP.CATID=AU.CATID AND AU.USERID='1' GROUP BY EP.CATID HAVING EP.USERID='1' OR (EP.USERID=0 AND EP.CATTYPEID=1 AND EP.CATUSERTYPEID='2') ORDER BY EP.REORDER, EP.CATID Code