我写的查询语句 select t.company,t.deptment,count(t.deptment) from table t group by grouping sets((t.company,t.deptment)) 为什么总是多出t.company的行数,怎么能把这行去掉? 谢谢~
--不去重复 select id , company , count(deptment) from table group by id , company --去重复 select id , company , count(distinct deptment) from table group by id , company
select company ,count(distinct deptment) from table where company=(select company from table where id=已知id) group by company;先根据已知ID找出company再根据company统计不同的deptment数
select distinct company,count(deptment) over(partition by company) from table1 where id=xxx
select count(1) from table1 where id=xxx group by company
select t.company,t.deptment,count(t.deptment) from table t group by
grouping sets((t.company,t.deptment)) 为什么总是多出t.company的行数,怎么能把这行去掉?
谢谢~
select id , company , count(deptment) from table group by id , company
--去重复
select id , company , count(distinct deptment) from table group by id , company
where company=(select company from table where id=已知id)
group by company;先根据已知ID找出company再根据company统计不同的deptment数