+ -
当前位置:首页 → 问答吧 → oracle查询时将多条记录合并成一条,急急急急!!!

oracle查询时将多条记录合并成一条,急急急急!!!

时间:2011-09-26

来源:互联网

各位大哥:
   
有如下数据结构:
code brand name quant ordernum createTime did type 
750 联想 联想-TD80t-黑 73 1 2011-09-01 1 001
750 联想 联想-TD80t-黑 73 1 2011-09-06 1 001


请问如何合并成如下一条数据 (其中日期(createTime)为动态的)

code type brand name quant 2011-09-01 2011-09-06 did 
750 001 联想 联想-TD80t-黑 73 1 1 1


其中2011-09-01下对应的1为ordernum的值(2011-09-06雷同)

作者: xtyni129   发布时间: 2011-09-26

SQL code
select code,brand,name,quant,
max(decode(createTime,'2011-09-01',ordernum,0)) as 2009-09-01,
max(decode(createTime,'2011-09-06',ordernum,0)) as 2009-09-06,
did,type
from tab
group by code,brand,name,quant,did,type

作者: java3344520   发布时间: 2011-09-26