读书人

如果表中没有某几条记录就插入进去

发布时间: 2012-01-18 00:23:26 作者: rapoo

如果表中没有某几条记录,就插入进去,该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
)

读书人网 >SQL Server

热点推荐