如何能设计一个定时触发器,实现以下功能!表A:
no name price pricedatetime
001 长虹 12120 2007-09-27:11:11:11
002 海信 16230 2007-09-27:12:11:11
003 长虹 13320 2007-09-27:10:11:11
004 海尔 15450 2007-09-27:13:11:11
....该表为电视报价管理系统,即时更新,每天都要变好几次
本人想建一个触发器,让它能在每天零点把前一天各款电视的报价记录在单独一个统计表中B:
B的结构与A表一样(区别是name不重复,只记录同类产品的平均价):
no name price pricedatetime
001 海信 16230 2007-09-27
002 长虹 12720 2007-09-27
003 海尔 15450 2007-09-27
....
no name price pricedatetime
001 长虹 12120 2007-09-27:11:11:11
002 海信 16230 2007-09-27:12:11:11
003 长虹 13320 2007-09-27:10:11:11
004 海尔 15450 2007-09-27:13:11:11
....该表为电视报价管理系统,即时更新,每天都要变好几次
本人想建一个触发器,让它能在每天零点把前一天各款电视的报价记录在单独一个统计表中B:
B的结构与A表一样(区别是name不重复,只记录同类产品的平均价):
no name price pricedatetime
001 海信 16230 2007-09-27
002 长虹 12720 2007-09-27
003 海尔 15450 2007-09-27
....
no name price pricedatetime
001 长虹 12120 2007-09-27:11:11:11
002 海信 16230 2007-09-27:12:11:11
003 长虹 13320 2007-09-27:10:11:11
004 海尔 15450 2007-09-27:13:11:11
------------
select
id=identity(int,1,1),
name ,
avg(price)as price
into #t
from A
where datediff(day,pricedatetime,getdatde())=1
group by nameinsert into B
select * from #tdrop table #t
no=max(no),--不知道你怎么取,海信本来是002变成了001
name,
price=avg(price),
pricedatetime=convert(varchar(10),dateadd(day,-1,getdate()),120)
from A
where datediff(day,pricedatetime,getdate())=1
group by name
id=identity(int,1,1),
name ,
avg(price)as price
into #t
from A
where datediff(day,pricedatetime,getdatde())=1
group by nameinsert into B
select * ,convert(varchar(10),dateadd(day,-1,getdate()),120)from #tdrop table #t