上面一张图是要得到的结果,下面是要查询的表。
解决方案
10
select problem_mode, count(case when month(problem_date)=1 then 1 end) as n1, count(case when month(problem_date)=2 then 1 end) as n2, ...... from fixture_repires where year(problem_date)=2015 group by problem_mode
3
http://blog.csdn.net/acmain_chm/article/details/4283943
MySQL交叉表
在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx( id int primary key, c1 c…
MySQL交叉表
在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义。http://topic.csdn.net/u/20090530/23/0b782674-4b0b-4cf5-bc1a-e8914aaee5ab.html?96198现整理解法如下:数据样本: create table tx( id int primary key, c1 c…
6
select problem_mode,sum(case when problem_date >= "2015-01-01" and problem_date < "2015-02-01" then 1 else 0 end)jan from fixture_repires group by problem_mode; 其它月份、一年的以此类推。
1
2楼正解,本人测试过,
select problem_mode,
count(case when month(problem_date)=1 then 1 end) as n1,
count(case when month(problem_date)=2 then 1 end) as n2,
……
from fixture_repires
where year(problem_date)=2015
group by problem_mode
select problem_mode,
count(case when month(problem_date)=1 then 1 end) as n1,
count(case when month(problem_date)=2 then 1 end) as n2,
……
from fixture_repires
where year(problem_date)=2015
group by problem_mode