求一sql语句....(高手请进)
两个A表和B表.A表中有ID,Count列,B表中含有ID,Count,Img列.要求当B中任何记录中的Count> 100时则把记录(ID,Count)无重复地地添加到A表中....请各位高手指点下
<没分了不好意思>
------解决方案--------------------select id,count into A(id,count) from B where B.Count> 100
------解决方案--------------------不知道你要的是哪一种:
一.
select distinct B.ID,B.count
into A(ID,count) from B where B.count> 100 and B.ID not in (select id from A
二.
select distinct B.ID,B.count
into A(ID,count) from B where B.count> 100 and B.ID,B.count not in (select A.ID,A.count from A)
------解决方案--------------------对于SQL Server,应该为B定义触发器,类似于:
Create trigger adfasdfadf on B after insert --仅仅insert?
as
update A set count=i.count
from inserted as i inner join A on i.id=A.id
insert A(id,count) select id,count from inserted as i where not exists
(select * from A where id=i.id)
go
具体说明到数据库论坛上问问。这里是asp.net论坛,我就不解释了。
------解决方案--------------------Create trigger adfasdfadf on B after insert --仅仅insert?
as
update A set count=i.count
from inserted as i inner join A on i.id=A.id
where i.count> 100
insert A(id,count) select id,count from inserted as i where count> 100 and not exists
(select * from A where id=i.id)
go