select t.project_id,t.project_stage,count(*) group by t.project_id,t.project_stage这个sql可以查出分组合计值,如下:
项目A stageA 12
项目A stageB 3
项目A stageC 6
项目B stageB 8但我们想直接获得这样的结果:[因为stage是固定的。]项目A 12 3 6
项目B 0 8 0请问这样的SQL怎么写?
项目A stageA 12
项目A stageB 3
项目A stageC 6
项目B stageB 8但我们想直接获得这样的结果:[因为stage是固定的。]项目A 12 3 6
项目B 0 8 0请问这样的SQL怎么写?
解决方案 »
- OTL(Version 4.0.179) 出现段错误
- 请教这样的视图能建吗?该如何建
- 求助oracle10i網絡教程,希望那位有的兄弟分享一下。
- ORA-01033: ORACLE initialization or shutdown in progress,shutdown abort>startup试过也不行。。。
- [菜鸟来咧]请问谁能?
- 一个特殊的UPDATE
- 请教高手::如何查看某oracle实例下面定义了多少jobs????
- 请问我要如何把sql server的数据转移到oracle上啊,谢谢!
- 关于oracle数据库中序列的问题
- oracle 11g安装不了,到选择桌面类时自动退出
- oracle/dms/instrument/ExecutionContextForJDBC 驱动出了问题?
- 请教Between函数的用法 在线等! QQ:15493898
count(decode(project_stage,'stageB',1)) as countB
count(decode(project_stage,'stageC',1)) as countC
from tablename
group by project_id
count(decode(project_stage,'stageB',1)) as countB,
count(decode(project_stage,'stageC',1)) as countC
from tablename
group by project_id
project_id,
stageA = sum(decode(project_id,'stageA',1,0)),
stageB = sum(decode(project_id,'stageB',1,0)),
stageC = sum(decode(project_id,'stageC',1,0))
from
tabname
group by
project_id
project_id,
sum(decode(project_id,'stageA',1,0)) as stageA,
sum(decode(project_id,'stageB',1,0)) as stageB,
sum(decode(project_id,'stageC',1,0)) as stageC
from
tabname
group by
project_id
project_id,
sum(case when project_id='stageA' then 1 else 0 end) stageA,
sum(case when project_id='stageB' then 1 else 0 end) stageB,
sum(case when project_id='stageC' then 1 else 0 end) stageC
from tabname
group by project_id