您的位置:首页 > 其它

count(distinct xxx) 与distinct ; count(case when )

2013-05-02 09:30 399 查看
select a,b,c

select a,b,distinct c   不对 distinct必须是对所有字段排重,必须写在外面。

select distinct a,b,c

第二种   也叫转置   主要理解意思

select a,count(distinct b) ....group by a

按照a,汇总不同的b。

1    1

1    2

1    3

1    2

汇总后:

1   3

count(distinct case when time_measure = '>1' then ISR else null end)   去排重 汇总

sum(case when time_measure = '>1' then 1 else 0 end )  汇总不排重
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: