触发器(五)Trigger_Insert_VocHour

来源:互联网 发布:天行健君电子商务软件 编辑:程序博客网 时间:2024/06/15 17:11
USE [AirDB_YiZhuang]
GO


/****** Object:  Trigger [dbo].[Trigger_Insert_VocHour]    Script Date: 2017/12/25 16:54:10 ******/
SET ANSI_NULLS ON
GO


SET QUOTED_IDENTIFIER ON
GO






-- =============================================
-- Author: pyy
-- Create date: 2016-9-27
-- Description: VocMin数据求平均得到hour
---- mondify Description: 2017-4-5站点“宾士国际”的数据只更新到了3-28
--DATEADD(hour,1,cast(MONIDATE as datetime))小时求平均,加1小时
--where MONIDATE >=(select DATEADD(HOUR,1,max(MONIDATE)) from T_Data_VocHour不用加1了
--where MONIDATE >=(select max(MONIDATE) from T_Data_VocHour)
-- =============================================
CREATE TRIGGER [dbo].[Trigger_Insert_VocHour] 
   ON  [dbo].[T_Data_VocMin]
   AFTER INSERT--,DELETE,UPDATE
AS 
BEGIN
declare @t1 datetime
declare @t2 datetime
declare @Mint datetime
--站点1的最新时间
set @t1=(select max(MONIDATE) from [AirDB_YiZhuang].[dbo].[T_Data_VocMin] where STATIONCODE= '500000001')
--编号写错了5000001
--站点2的最新时间
set @t2=(select max(MONIDATE) from [AirDB_YiZhuang].[dbo].[T_Data_VocMin] where STATIONCODE= '500000002')
--5000002
--最新时间里的最小值
set @Mint=@t1
--(select case when @t1<@t2 then @t1 else @t2 end)
insert into [AirDB_YiZhuang].[dbo].[T_Data_VocHour]
(STATIONCODE,MONIDATE,Vinyl_chloride,Butadiene,Ethylene,
ethane,Propane,propylene,butylene,twoButene,cistwoButene,transtwoPentene,cistwoPentene,onePentene,
Isoprene,IsoButene,nbutane,Isopentane,nPentane,dimethylbutane,symDichloroethane,Methylpentane,
nHexane,Benzene,cyclohexane,nHeptane,octane,nNonane,Cumene,nPropylbenzene,trimethylbenzene,
Mesitylene,Chlorobenzene,jiandichlorobenzene,duidichlorobenzene,lindichlorobenzene,tetrachloroethylene,
trichloroethylene,cyclopentane,decane,Diethylbenzene,duiDiethylbenzene,ttdimethylpentane,tfdimethylpentane,
methylcyclopentane,methylheptane,methylhexane,trimethylpentane,undecane)
select STATIONCODE,DATEADD(hour,1,cast(MONIDATE as datetime)) MONIDATE,Vinyl_chloride,Butadiene,Ethylene,
ethane,Propane,propylene,butylene,twoButene,cistwoButene,transtwoPentene,cistwoPentene,onePentene,
Isoprene,IsoButene,nbutane,Isopentane,nPentane,dimethylbutane,symDichloroethane,Methylpentane,
nHexane,Benzene,cyclohexane,nHeptane,octane,nNonane,Cumene,nPropylbenzene,trimethylbenzene,
Mesitylene,Chlorobenzene,jiandichlorobenzene,duidichlorobenzene,lindichlorobenzene,tetrachloroethylene,
trichloroethylene,cyclopentane,decane,Diethylbenzene,duiDiethylbenzene,ttdimethylpentane,tfdimethylpentane,
methylcyclopentane,methylheptane,methylhexane,trimethylpentane,undecane
from
(select STATIONCODE,
substring(convert(varchar,MONIDATE,120),0,14)+':00:00' MONIDATE,
AVG(Vinyl_chloride) Vinyl_chloride,AVG(Butadiene) Butadiene,
AVG(Ethylene) Ethylene,AVG(ethane) ethane,
AVG(Propane) Propane,AVG(propylene) propylene,
AVG(butylene) butylene,AVG(twoButene) twoButene,
AVG(cistwoButene) cistwoButene,AVG(transtwoPentene) transtwoPentene,
AVG(cistwoPentene) cistwoPentene,AVG(onePentene) onePentene,
AVG(Isoprene) Isoprene,AVG(IsoButene) IsoButene,
AVG(nbutane) nbutane,AVG(Isopentane) Isopentane,
AVG(nPentane) nPentane,AVG(dimethylbutane) dimethylbutane,
AVG(symDichloroethane) symDichloroethane,AVG(Methylpentane) Methylpentane,


AVG(nHexane) nHexane,AVG(Benzene) Benzene,
AVG(cyclohexane) cyclohexane,AVG(nHeptane) nHeptane,
AVG(octane) octane,AVG(nNonane) nNonane,
AVG(Cumene) Cumene,AVG(nPropylbenzene) nPropylbenzene,
AVG(trimethylbenzene) trimethylbenzene,AVG(Mesitylene) Mesitylene,
AVG(Chlorobenzene) Chlorobenzene,AVG(jiandichlorobenzene) jiandichlorobenzene,
AVG(duidichlorobenzene) duidichlorobenzene,AVG(lindichlorobenzene) lindichlorobenzene,
AVG(tetrachloroethylene) tetrachloroethylene,AVG(trichloroethylene) trichloroethylene,
AVG(cyclopentane) cyclopentane,AVG(decane) decane,
AVG(Diethylbenzene) Diethylbenzene,AVG(duiDiethylbenzene) duiDiethylbenzene,


AVG(ttdimethylpentane) ttdimethylpentane,AVG(tfdimethylpentane) tfdimethylpentane,
AVG(methylcyclopentane) methylcyclopentane,AVG(methylheptane) methylheptane,
AVG(methylhexane) methylhexane,AVG(trimethylpentane) trimethylpentane,
AVG(undecane) undecane




from 
[dbo].[T_Data_VocMin]
where MONIDATE >=(select max(MONIDATE) from T_Data_VocHour)
--T_MID_AIRQUALITYHOUR最新的时间
 and 
 --MONIDATE <(select substring(convert(varchar,max(monidate),120),0,14)+':00:00' from T_Data_VocMin)
--T_MID_AIRQUALITYMin最新的时间的小时值
--当两个站点的分钟数据不同步的时候,数据慢的那个站点的小时平均数据就可能不对(不足60条分钟数据)
MONIDATE <(substring(convert(varchar,@Mint,120),0,14)+':00:00')
group by STATIONCODE,substring(convert(varchar,MONIDATE,120),0,14)) as a


END






GO



阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 泪水之池任务怎么做 擦干你的泪水 泪水将我淹没到底谁该难过 强忍泪水表情包 空洞骑士泪水之城 擦干泪水歌曲原唱 强忍泪水图片 十万毫升泪水 以泪水为话题的作文 十万毫升泪水歌词 我的青春里有泪水 我的眼里常含泪水 为什么眼里常含泪水 为什么我眼里常含泪水下一句 为什么我眼里常含泪水 为什么我的眼睛常含泪水 泪沟消除 泪沟怎么办 泪沟是什么 打完泪沟恢复过程图片 泪沟纹图片 泪沟填充失败案例图 泪沟填充哪种好 填泪沟用什么玻尿酸好 填充泪沟型黑眼圈 眼袋与泪沟 添泪沟 泪沟去除 不整容泪沟怎么去除 怎样去泪沟 怎么去泪沟小窍门 怎么去泪沟 泪沟填充前后对比 怎么去除泪沟 去除泪沟有什么妙招 怎么消除泪沟 天生泪沟怎么去除 如何去除泪沟 泪沟黑眼圈 如何消除泪沟 去除泪沟