时间:2021-07-01 10:21:17 帮助过:5人阅读
以三个站点三个参数为例 1、以参数当列时 select zad_time,zad_sid,zad_data1,zad_data2,zad_data3,zad_data4 from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_sid in(000000,000001,000002) and zad_time='20130416' 2、以参数当行时 select * f
以三个站点三个参数为例
1、以参数当列时
select zad_time,zad_sid,zad_data1,zad_data2,zad_data3,zad_data4 from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_sid in(000000,000001,000002) and zad_time='20130416'
2、以参数当行时
select * from ( select zad_time,zad_sid,参数='SO2', 浓度值 = zad_data1 from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_time='20130416' and zad_sid in('000000','000001','000002') union all select zad_time,zad_sid,参数='NO2', 浓度值 = zad_data2 from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_time='20130416' and zad_sid in('000000','000001','000002') union all select zad_time,zad_sid,参数='PM10', 浓度值 = zad_data3 from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_time='20130416' and zad_sid in('000000','000001','000002') ) t order by zad_time
以站点当列时
select zad_time,参数,供销商城,ssss,dddd from ( select zad_time,参数='SO2',sum(case zad_sid when '000000' then zad_data1 end) as '供销商城',sum(case zad_sid when '000001' then zad_data1 end) as 'ssss', sum(case zad_sid when '000002' then zad_data1 end) as 'dddd' from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_time='20130416' group by zad_time union all select zad_time,参数='NO2',sum(case zad_sid when '000000' then zad_data2 end) as '供销商城',sum(case zad_sid when '000001' then zad_data2 end) as 'ssss', sum(case zad_sid when '000002' then zad_data2 end) as 'dddd' from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_time='20130416' group by zad_time union all select zad_time,参数='PM10',sum(case zad_sid when '000000' then zad_data3 end) as '供销商城',sum(case zad_sid when '000001' then zad_data3 end) as 'ssss', sum(case zad_sid when '000002' then zad_data3 end) as 'dddd' from [XHAQMMS_CDB].[dbo].[XHZ_T_DAYREP_AQI_XZ] where zad_time='20130416' group by zad_time ) t order by zad_time
,网站空间,香港服务器,虚拟主机