ORACLE分组查询的问题~

moonshowder 2008-01-26 03:31:00
有table表下id,company,deptment 3个列。
如何在知道id的情况下,根据id查询出各个company下的deptment的个数?
deptment有重复。
谢谢 ,在线等~
...全文
1105 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ypopo1234 2009-02-26
  • 打赏
  • 举报
回复
select count(1) from table1 where id=xxx group by company
sinusoid 2008-01-26
  • 打赏
  • 举报
回复
select distinct company,count(deptment) over(partition by company) from table1 where id=xxx
weifengxian2 2008-01-26
  • 打赏
  • 举报
回复
select company ,count(distinct deptment) from table
where company=(select company from table where id=已知id)
group by company;

先根据已知ID找出company再根据company统计不同的deptment数
dawugui 2008-01-26
  • 打赏
  • 举报
回复
--不去重复
select id , company , count(deptment) from table group by id , company
--去重复
select id , company , count(distinct deptment) from table group by id , company
fxianxian 2008-01-26
  • 打赏
  • 举报
回复
表結構,還有給點數據啊!
moonshowder 2008-01-26
  • 打赏
  • 举报
回复
我写的查询语句
select t.company,t.deptment,count(t.deptment) from table t group by
grouping sets((t.company,t.deptment)) 为什么总是多出t.company的行数,怎么能把这行去掉?
谢谢~

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧