select s.name, sum(if(o.cp>0,1,0)) as c, sum(if(o.cp=0,1,0)) as h, sum(o.p) as p, sum(o.u) as u, published,s.id from table_s as s inner join table_o as o on s.middle=o.middle group by s.name where published = 1 ORDER BY s.id asc
ÉÏÃæµÄsqlÓï¾ä È¥µô where published =1 ¾ÍÊǶԵ쬼ÓÉÏÕâ¸öwhere published =1 ¾Í´íµÄ¡£
´íÔÚÄÄÄØ£¿ÕÒ°ëÌ죬ÕÒ²»µ½£¬¸ßÊÖÖ¸½Ìһϡ£Ð»Ð»SQL code: select s.name, sum(if(o.cp>0,1,0)) as c, sum(if(o.cp=0,1,0)) as h, sum(o.p) as p, sum(o.u) as u, published,s.id from table_s as s inner join table_o as o on s.middle=o.middle where published = 1 -- where ±ØÐëÔÚgroup by ֮ǰ¡£ group by s.name ORDER BY s.id asc
ÎĵµÖÐÓÐSELECTºÍÆäËüÓï¾äµÄÓï·¨½éÉÜ¡£
MySQL¹Ù·½Îĵµ http://dev.mysql.com/doc/refman/5.1/zh/index.html SQL code: select s.name, sum(if(o.cp>0,1,0)) as c, sum(if(o.cp=0,1,0)) as h, sum(o.p) as p, sum(o.u) as u, published,s.id from table_s as s inner join table_o as o on s.middle=o.middle where published = 1 group by s.name ORDER BY s.id asc