首页 > 数据库技术 > 详细

php MYSQL 一条语句中COUNT出不同的条件

时间:2016-04-16 18:27:56      阅读:221      评论:0      收藏:0      [点我收藏+]
 SELECT DISTINCT c.uid, count( 1 ) AS zongji, count( if( task_type = ‘mobile‘, true, NULL ) ) AS 

mobile, count( if( task_type = ‘computer‘, true, NULL ) ) AS computer
FROM keke_witkey_task_work AS c
WHERE c.op_status >0
AND c.free_price >3
AND c.work_time >= ‘1460176800‘
AND c.work_time <= ‘1460736000‘
GROUP BY c.uid
ORDER BY mobile DESC
LIMIT 30 

 uid(用户ID)
task_type(任务类型(a,b,c,d))
需求是:按时间段,等要求,统计出每个用户 各任务类型的记录数

php MYSQL 一条语句中COUNT出不同的条件

原文:http://www.cnblogs.com/ycookie/p/5398962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!