id type resource
1 1 1
1 1 1
2 2 2
select id,count(distinct resource) as c
from tab_name
where type=1
group by id;
id c
1 2
我想让其显示为
id c
1 2
2 0
希望我的问题描述清楚
[b]问题补充:[/b]
回复一楼:
条件不能去掉
id type resource
1 1 1
1 1 1
2 2 2
select id,count(distinct resource) as c
from tab_name
where type=1
group by id;
id c
1 2
我想让其显示为
id c
1 2
2 0
希望我的问题描述清楚
[b]问题补充:[/b]
回复一楼:
条件不能去掉
没看清需求不好意思.....
[code="sql"]
select a.id,
count(distinct case type when 1 then resource else NULL END) as c
from tab_name a
group by id
[/code]