当前位置: 代码迷 >> Sql Server >> 如果表中没有某几条记录,就插入进去,该SQL如何写
  详细解决方案

如果表中没有某几条记录,就插入进去,该SQL如何写

热度:48   发布时间:2016-04-27 20:26:46.0
如果表中没有某几条记录,就插入进去,该SQL怎么写?
例如:

sno               name                             sd
1041 赵国庆         通信            
1041 赵国庆         会计  


当1041号没有学过“计算机”、“网络”课程的,那么就插入2条记录
sno               name                             sd
1041 赵国庆         通信            
1041 赵国庆         会计  
1041 赵国庆         计算机  
1041 赵国庆         网络
 



------解决方案--------------------
有没有个课程表

如果有
insert tablename
select distinct a.sno,a.name,b.sd
from tablename a,课程表 b
where not exists (
select 1 from tablename
where sno=a.sno
and sd=b.sd
)
  相关解决方案