oracle单表查询需要用对一列拆分,如何处理呀。

alexzhu1973 2008-04-25 04:02:23
Table1
Id name status type
1 a start 1
2 b end 2
3 a start 1
4 b end 2
5 a start 1
6 b end 2
7 a start 1
8 b end 2


期望结果:

Status=‘start’并且count(type=1)count(type=2)
Group by name
得到列为:
Name 时长 type1次数合计 type2次数合计

我用
Select t.name,count(status) s1,sum(type=1) t1,sum(type=2) t2
From table1 t
where status=’start’
group by name
不正确

请问这个语句怎么写呀?
...全文
96 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
UltraBejing 2008-05-01
  • 打赏
  • 举报
回复
有点难度哦
knowledge_Is_Life 2008-04-30
  • 打赏
  • 举报
回复
这个简单啊,网上搜一下就得到答案了.
panxuan 2008-04-26
  • 打赏
  • 举报
回复

Select distinct t.name,count(status) s1,sum(decode(type,1,1,0)) t1,sum(decode(type,2,1,0)) t2 From table1 t where status=’start’ group by name
panxuan 2008-04-26
  • 打赏
  • 举报
回复
使用distinct
alexzhu1973 2008-04-25
  • 打赏
  • 举报
回复
我实际表格group by的列有3列
用楼上的方法试过,有许多重复列怎么去除呀
hebo2005 2008-04-25
  • 打赏
  • 举报
回复
Select t.name,count(status) s1,sum(decode(type,1,1,0)) t1,sum(decode(type,2,1,0)) t2
From table1 t
where status=’start’
group by name
ahua3515 2008-04-25
  • 打赏
  • 举报
回复
select t.name,status,sum(decode(type,1,1,2,0),sum(decode(type,2,1,1,0)) from talbe1 t where status='start' group by name,status

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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