1.cast拼接
select value, cast(cast(date_year as VARCHAR(10))+'-'+cast(date_month as VARCHAR(10))+'-'+cast(date_day as VARCHAR(10))+' '+cast(date_hours as VARCHAR(10))+':00:00.000' as DATEtime ) date from(select date_hours,date_day,date_month,date_year ,sum(n_value) as 'value' from pro_statistics_hours WHERE meter_no IN ('ELEC_N2_P02_3','ELEC_N2_P01_5') GROUP BY date_hours,date_day,date_month,date_year ) AS T ORDER BY date
#拼接时间
2.in函数
WHERE meter_no IN ('ELEC_N2_P02_3','ELEC_N2_P01_5')
3.清空表
TRUNCATE TABLE pro_ahu_temp
4.取前几个记录
SELECT TOP number/percent column_name(s) FROM table_name
5.查询条件
select top 1* from pro_ahu_minute_energy_real WHERE ( ahu_no='AHU_L5_000' or ahu_no='AHU_L5_006') and n_hour=8 ORDER BY insertTime ASC
-- select top 1 start_value from pro_ahu_minute_energy_real WHERE ( ahu_no='AHU_L5_000' or ahu_no='AHU_L5_006') and n_hour=8 ORDER BY insertTime ASC
-- select * from pro_ahu_minute_energy_real WHERE(ahu_no='AHU_L5_000' or ahu_no='AHU_L5_006') and n_hour=8 ORDER BY insertTime DESC
-- select top 1 end_value from pro_ahu_minute_energy_real WHERE ( ahu_no='AHU_L5_000' or ahu_no='AHU_L5_006') and n_hour=8 ORDER BY insertTime DESC
select * from pro_ahu_minute_energy_real WHERE (ahu_no='AHU_L5_000' or ahu_no='AHU_L5_006') and n_hour=8 and n_day=5 and n_month=6 and n_year=2019 ORDER BY insertTime ASC