java中纵表转横表_纵表转换为横表

纵表格式:

pid                 dtag  ttag  dqf    pval

1001-1-1001    100    1       0    10.10

横表格式:

pid    h1  h2  h3

Select --Pid,Substr(Pid, 8, 4) As Dev_Type,

Substr(Pid, 0, 6) As Dev_Type,

To_Char(To_Date('20000101', 'yyyymmdd') + Dtag, 'YYYY-MM-DD') || ' ' ||

Trunc(Ttag / 60) || ':00:00' As Datetime,

-- Dtag, Ttag,

Sum(Case Substr(Pid, 8, 4)

When '1001' Then

Pval

Else

0

End) As Cy1,

Sum(Case Substr(Pid, 8, 4)

When '1002' Then

Pval

Else

0

End) As Cy2,

Sum(Case Substr(Pid, 8, 4)

When '1003' Then

Pval

Else

0

End) As Cy3,

Sum(Case Substr(Pid, 8, 4)

When '1004' Then

Pval

Else

0

End) As Cy4,

Sum(Case Substr(Pid, 8, 4)

When '1005' Then

Pval

Else

0

End) As Cy5,

Sum(Case Substr(Pid, 8, 4)

When '1006' Then

Pval

Else

0

End) As Cy6,

Sum(Case Substr(Pid, 8, 4)

When '1007' Then

Pval

Else

0

End) As Cy7,

Sum(Case Substr(Pid, 8, 4)

When '1008' Then

Pval

Else

0

End) As Cy8,

Sum(Case Substr(Pid, 8, 4)

When '1009' Then

Pval

Else

0

End) As C2h2,

Sum(Case Substr(Pid, 8, 4)

When '1010' Then

Pval

Else

0

End) As C2h6,

Sum(Case Substr(Pid, 8, 4)

When '1011' Then

Pval

Else

0

End) As Cy11,

Sum(Case Substr(Pid, 8, 4)

When '1012' Then

Pval

Else

0

End) As Cy12,

Sum(Case Substr(Pid, 8, 4)

When '1013' Then

Pval

Else

0

End) As Cy13,

Sum(Case Substr(Pid, 8, 4)

When '1014' Then

Pval

Else

0

End) As Cy14,

Sum(Case Substr(Pid, 8, 4)

When '1015' Then

Pval

Else

0

End) As Cy15,

Sum(Case Substr(Pid, 8, 4)

When '1016' Then

Pval

Else

0

End) As Cy16,

Sum(Case Substr(Pid, 8, 4)

When '1017' Then

Pval

Else

0

End) As Cy17,

Sum(Case Substr(Pid, 8, 4)

When '1018' Then

Pval

Else

0

End) As Cy18,

Sum(Case Substr(Pid, 8, 4)

When '1019' Then

Pval

Else

0

End) As Cy19

From Analog_Data_200701

--Where Dtag = '2558' And Ttag = '240' And Substr(Pid, 0, 6) = '1001-4'

Group By Substr(Pid, 0, 6), Dtag, Ttag --, Pval

Order By Dtag, Ttag, Substr(Pid, 0, 6)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值