表1:
槽号 出铝量 日期
101 1800 2005-1-1
102 1700 2005-1-1
103 1800 2005-1-1
得到如下结果(统计个数):
【1780,+】 【1750,1780】 【1650,1750】 【-,1650】
日期 一区 二区 三区 一区 二区 三区 一区 二区 三区 一区 二区 三区
2005-1-1 2 0 0 0 0 0 1 0 0 0 0 0
槽号以一开头的就是一区,依次类推,301就是三区的槽号。
谢谢各位了
槽号 出铝量 日期
101 1800 2005-1-1
102 1700 2005-1-1
103 1800 2005-1-1
得到如下结果(统计个数):
【1780,+】 【1750,1780】 【1650,1750】 【-,1650】
日期 一区 二区 三区 一区 二区 三区 一区 二区 三区 一区 二区 三区
2005-1-1 2 0 0 0 0 0 1 0 0 0 0 0
槽号以一开头的就是一区,依次类推,301就是三区的槽号。
谢谢各位了
日期
,sum(CASE WHEN 出铝量>=1780 and 槽号=101 THEN 1 ELSE 0 END) as '【1780,+】一区'
,sum(CASE WHEN 出铝量>=1780 and 槽号=102 THEN 1 ELSE 0 END) as '【1780,+】二区'
,
....
别指望sql了
日期
,sum(CASE WHEN 出铝量>=1780 and 槽号=101 THEN 1 ELSE 0 END) as '【1780,+】一区'
,sum(CASE WHEN 出铝量>=1780 and 槽号=102 THEN 1 ELSE 0 END) as '【1780,+】二区'
,
....
,nvl(sum(decode(b.区号,1,1,0)),0) as '【1780,+】一区'
,nvl(sum(decode(b.区号,2,1,0)),0) as '【1780,+】二区'
,nvl(sum(decode(b.区号,3,1,0)),0) as '【1780,+】三区'
,nvl(sum(decode(c.区号,1,1,0)),0) as '【1750,1780】一区'
,nvl(sum(decode(c.区号,2,1,0)),0) as '【1750,1780】二区'
,nvl(sum(decode(c.区号,3,1,0)),0) as '【1750,1780】三区'
,nvl(sum(decode(d.区号,1,1,0)),0) as '【1650,1750】一区'
,nvl(sum(decode(d.区号,2,1,0)),0) as '【1650,1750】二区'
,nvl(sum(decode(d.区号,3,1,0)),0) as '【1650,1750】三区'
,nvl(sum(decode(e.区号,1,1,0)),0) as '【-,1650】一区'
,nvl(sum(decode(e.区号,2,1,0)),0) as '【-,1650】二区'
,nvl(sum(decode(e.区号,3,1,0)),0) as '【-,1650】三区'
from (select distinct 日期 from 表1) a
,(select 日期,substr(槽号,1,1) 区号 from 表1 where 出铝量>=1780) b
,(select 日期,substr(槽号,1,1) 区号 from 表1 where 出铝量>=1750 and 出铝量<1780) c
,(select 日期,substr(槽号,1,1) 区号 from 表1 where 出铝量>=1650 and 出铝量<1750) d
,(select 日期,substr(槽号,1,1) 区号 from 表1 where 出铝量<1650) e
where a.日期=b.日期(+)
and a.日期=c.日期(+)
and a.日期=d.日期(+)
and a.日期=e.日期(+)
group by a.日期