求教一个sql语句的写法

来源:百度知道 编辑:UC知道 时间:2024/05/26 06:20:28
一个表A,里边有name,count字段。count字段可以取2个值:0或者1。现在我想取出name、值为0的记录的条数、值为1的记录的条数,然后group by name。谢谢诸位大侠

select name,count(*) cc,'0' as coh from A where [count] = '0' group by name
union
select name,count(*) cc ,'1' as coh from A where [count] = '1' group by name order by [name]

select Name,
[0记录]=sum(case when [count]=0 then 1 else 0 end),
[1记录]=sum([count] )
from A
group by Name

select name,count(*),'0' from 表A where count字段=0 group by name
union
select name,count(*),'1' from 表A where count字段=1 group by name

select count(*) from A where name=0

select name,
sum(case when count = 0 then 1 else 0 end),
sum(case when count = 1 then 1 else 0 end)
from A
group by name