Group by 后 细分数据
本帖最后由 Mark_ZYW 于 2013-01-07 18:55:25 编辑
select cartypesn,
sum(case w2_onschedule_sort when 10 then 1 else 0 end) 提前入库,
sum(case w2_onschedule_sort when 20 then 1 else 0 end) 计划内入库,
sum(case when w2_onschedule_sort in (30,40) then 1 else 0 end) 延迟入库
from w2summary_day_h_d m group by cartypesn;
有没有办法将 提前入库、 计划内入库、延迟入库
在进行细分 得到 A有多少 B有多少 ?
大虾 帮我看看 急!!!!!!!
------解决方案--------------------单独汇总吗?group by rollup(A,B);
------解决方案--------------------WITH TEST AS (
SELECT 'A' AS X,'10' AS Y,'1' AS Z FROM DUAL
UNION ALL
SELECT 'A' AS X,'10' AS Y,'1' AS Z FROM DUAL
UNION ALL
SELECT 'A' AS X,'20' AS Y,'0' AS Z FROM DUAL
UNION ALL
SELECT 'A' AS X,'20' AS Y,'0' AS Z FROM DUAL
UNION ALL
SELECT 'A' AS X,'30' AS Y,'1' AS Z FROM DUAL
UNION ALL
SELECT 'B' AS X,'10' AS Y,'0' AS Z FROM DUAL
UNION ALL
SELECT 'B' AS X,'20' AS Y,'1' AS Z FROM DUAL
UNION ALL
SELECT 'C' AS X,'30' AS Y,'0' AS Z FROM DUAL
UNION ALL
SELECT 'C' AS X,'10' AS Y,'1' AS Z FROM DUAL
)
SELECT X,
MAX(DECODE(Y,'10',Z,0)) S1,
MAX(DECODE(Y,'20',Z,0)) S2,
MAX(DECODE(Y,'30',Z,0)) S3
FROM (
SELECT X,Y,COUNT(Z) Z FROM TEST GROUP BY X,Y) GROUP BY X
------解决方案--------------------我看楼主的描述是没有看懂,但看你写的sql语句是看明白了。学习了
------解决方案--------------------同楼上,描述没看懂,SQL看懂了。学习