sql语句:如何查数据库一个表中的一个行的不同项

2022-11-03 09:02

2022-11-03 13:52
select
max(case t.item1 when 'aa' then count(t.item1) else 0 end) aa,
max(case t.item1 when 'bb' then count(t.item1) else 0 end) bb,
max(case t.item1 when 'cc' then count(t.item1) else 0 end) cc
from 表1 t

group by t.item1
更多回答
select count(distinct ITEM1) from 表1
就能得出个数啦。
select t.item1, count(*) from 表1 t
group by t.item1