sql 语句的笔记

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值