22,280
社区成员
发帖
与我相关
我的任务
分享
--insert into C(学生ID , 课程ID)
select a.学生ID,b.课程ID
from A
inner join b
on 1=1 and a.学生名称 = 'xxx' and b.课程名称 = 'yyy'
where not exists(select 1 from c
where c.学生ID = a.学生ID and c.课程ID = b.课程ID)
--insert into C(学生ID , 课程ID)
select a.学生ID,b.课程ID
from A
cross join b
where a.学生名称 = 'xxx' and b.课程名称 = 'yyy'
当然这样也行:
--insert into C(学生ID , 课程ID)
select a.学生ID,b.课程ID
from A
inner join b
on 1=1 and a.学生名称 = 'xxx' and b.课程名称 = 'yyy'
insert into C(学生ID , 课程ID)
select a.学生ID,b.课程ID
from A
cross join b
select
a.学生名称,b.课程名称
from
a inner join c on a.学生ID=c.学生ID
inner join b on b.课程ID =c.课程ID
SELECT A.学生ID ,
B.课程ID
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY 学生ID ) ID ,
学生ID
FROM a
) A
INNER JOIN ( SELECT ROW_NUMBER() OVER ( ORDER BY 课程ID ) ID ,
课程ID
FROM B
) B ON A.ID = B.ID