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

 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))
需求是:按时间段,等要求,统计出每个用户 各任务类型的记录数

原文地址:https://www.cnblogs.com/ycookie/p/5398962.html