我有以下sql:
select ks2en,
count(case result when 'C-' then 1 end) as 'C-',
count(case result when 'C' then 1 end) as 'C',
count(case result when 'C+' then 1 end) as 'C+',
count(case result when 'B' then 1 end) as 'B',
count(case result when 'A' then 1 end) as 'A'
from student join subject
on subject.upn=student.upn
where name='English'
group by ks2en;
这会产生以下结果:
ks2en C- C C+ B A
0 3 0 0 0
2a 0 0 0 0 0
3a 18 0 0 0 0
3b 0 0 0 0 0
3c 0 0 0 0 0
4a 3 11 1 1 0
4b 3 3 36 0 0
4c 1 26 0 0 0
5b 0 3 0 1 0
5c 3 12 4 33 0
但是,我想生成列,以便在列没有总计的情况下,即列 A,那么它不应该显示。