SELECT MAX(C) AS MAX_REGISTER,R FROM (SELECT r.id_member R, COUNT(r.id_member) C FROM tb_register r JOIN tb_member m ON r.id_member=m.id_member WHERE r.id_type =1 AND m.level_member='1' AND m.year_member='2553' AND date_format(r.day_reg ,'%Y-%m') between '2010-05' and '2010-09' GROUP BY r.id_member) AS TB
ขึ้น error แบบข้างล่างนี้ล่ะครับ SQLError:Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
(SELECT r.id_member R, COUNT(r.id_member) C FROM tb_register r JOIN tb_member m ON r.id_member=m.id_member WHERE r.id_type =1 AND m.level_member='1' AND m.year_member='2553' AND date_format(r.day_reg ,'%Y-%m') between '2010-05' and '2010-09' GROUP BY r.id_member)
ส่วนของ subQuery ก็ปิดแล้วน่ะครับ
ถ้า query แค่
Code (PHP)
SELECT MAX(C) AS MAX_REGISTER FROM (SELECT COUNT(r.id_member) C FROM tb_register r JOIN tb_member m ON r.id_member=m.id_member WHERE r.id_type =1 AND m.level_member='1' AND m.year_member='2553' AND date_format(r.day_reg ,'%Y-%m') between '2010-05' and '2010-09' GROUP BY r.id_member) AS TB
//จะได้จำนวนที่ count ของแต่ละคน แล้วหา max
หรือ query
Code (PHP)
SELECT R FROM (SELECT r.id_member R FROM tb_register r JOIN tb_member m ON r.id_member=m.id_member WHERE r.id_type =1 AND m.level_member='1' AND m.year_member='2553' AND date_format(r.day_reg ,'%Y-%m') between '2010-05' and '2010-09' GROUP BY r.id_member) AS TB