带旋转
类似于以下内容:
select
count(case when id= 1 then 1 end) One,
count(case when id= 2 then 1 end) Two,
count(case when id= 3 then 1 end) Three,
count(case when id= 4 then 1 end) Four,
count(case when id= 5 then 1 end) Five,
count(case when id= 6 then 1 end) Six,
count(case when id= 7 then 1 end) Seven,
count(case when id= 8 then 1 end) Eight,
count(case when id= 9 then 1 end) Nine,
count(case when id= 10 then 1 end) Ten
from data;
结果:
ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN
4 1 0 0 0 0 0 0 0 1
无需旋转
您可以使用以下内容:
select id, count(*) as Count from data group by id;
结果将显示为:
id, count
1 5
2 8
3 9
4 15