Mysql数据表行转列统计判断

转载自:https://segmentfault.com/q/1010000009082729

这里写图片描述

这里写图片描述

select team_name,count(if(score='正','正','')) as'正',count(if(score='负','负','')) as '负' from teamscore group by team_name;

结合我自己的项目

这里写图片描述

想要把  同一positionId,和materialId 根据isClick true 和false  按照日期 进行统计 


select positionid,materialid,sum(if(isclick='true',1,0)) as'clickcount',sum(if(isclick='false',1,0)) as 'displaycount' 
from ads_log_record  where recordTime between '1804160900'  and   '1804161030' and positionid = '4'
group by positionid,materialid  

想要结果如下

这里写图片描述

猜你喜欢

转载自blog.csdn.net/sinat_32867867/article/details/80001966