SELECT a.user,count(b.order_id) as subcount,sum(if(b.verifysta='Y',1,0)) as passcount FROM vicidial_users a LEFT JOIN vicidial_order b on a.user = b.user WHERE a.user_group = 'TeamOne' GROUP BY a.user;
sum(if(b.verifysta='Y',1,0))
如果verifysta为Y,就加1,否则为0,
这个太棒了。
把逻辑放到sql中,会大大的减少程序的工作量,而且效率很高。
这样既能获取到全部的订单提交,也能获取审核通过的订单提交。
select a.user,a.full_name,count(b.order_id) as subcount,sum(if(b.verifysta='Y',1,0)) as passcount from vicidial_users a LEFT JOIN (SELECT user,order_id,verifysta from vicidial_order where time>UNIX_TIMESTAMP('2015-11-7') and timeUNIX_TIMESTAMP('2015-11-7') and timeUNIX_TIMESTAMP('2015-11-7') and time