SqlServer打横查询

SELECT t1.DATA_TIME,
MAX(CASE WHEN t1.AREA_ID='三里坪_0' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '三里坪_0',
MAX(CASE WHEN t1.AREA_ID='清江各流域_6' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '清江各流域_6',
MAX(CASE WHEN t1.AREA_ID='清江各流域_5' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '清江各流域_5',
MAX(CASE WHEN t1.AREA_ID='清江各流域_4' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '清江各流域_4',
MAX(CASE WHEN t1.AREA_ID='清江各流域_3' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '清江各流域_3',
MAX(CASE WHEN t1.AREA_ID='清江各流域_2' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '清江各流域_2',
MAX(CASE WHEN t1.AREA_ID='清江各流域_1' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '清江各流域_1',
MAX(CASE WHEN t1.AREA_ID='清江各流域_0' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '清江各流域_0',
MAX(CASE WHEN t1.AREA_ID='淋溪河_0' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '淋溪河_0',
MAX(CASE WHEN t1.AREA_ID='江坪河_0' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '江坪河_0',
MAX(CASE WHEN t1.AREA_ID='白水峪_0' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '白水峪_0',
MAX(CASE WHEN t1.AREA_ID='芭蕉河一级_0' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '芭蕉河一级_0',
MAX(CASE WHEN t1.AREA_ID='芭蕉河二级_0' THEN T1.AREA_RAIN_VALUE ELSE '0.00' END) AS '芭蕉河二级_0'

FROM T_GRIDAREARAIN t1
WHERE t1.DATA_TIME>='201803270800' AND t1.DATA_TIME<='201803280800'
GROUP BY t1.DATA_TIME
ORDER BY t1.DATA_TIME

 

 

posted @ 2018-03-27 09:38  unique1319  阅读(352)  评论(0编辑  收藏  举报