sql service 行轉列操作
阿新 • • 發佈:2018-03-06
ice pack 通過 group by img ora _id select package
通過行換列處理之後:
SELECT s.AREA_NAME,
max(CASE s.TYPE WHEN ‘CPU‘ THEN s.PRICE ELSE 0 end)CPU,
max(CASE s.TYPE WHEN ‘Bandwidth‘ THEN s.PRICE ELSE 0 end)Bandwidth,
max(CASE s.TYPE WHEN ‘Storage‘ THEN s.PRICE ELSE 0 end)Storage,
max(CASE s.TYPE WHEN ‘Memory‘ THEN s.PRICE ELSE 0 end)Memory
FROM (SELECT
a.AREA_NAME,
t.TYPE,
cast(t.PRICE as FLOAT) as PRICE
FROM
CSP_BASE_PRICE_INFO t,
SYS_AREA a
WHERE
a.AREA_ID = t.AREA_ID
AND t.TYPE IN (
‘CPU‘,
‘Bandwidth‘,
‘Storage‘,
‘Memory‘
)
AND T.PRICE_TYPE = ‘ToPackage‘) s
GROUP BY s.AREA_NAME
結果就變成下面這樣了
sql service 行轉列操作