您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mssql 两表合并sql语句

2024/6/28 20:06:49发布19次查看
mssql 两表合并sql语句,下面是简单的例子,大家可以参考下。
学生表: 课程表:
id 姓名 课程号(外键) 课程号,课程名
'1', 'xix', 1 1,' 语文'
'2', 'cic', 2 2, '数学'
'3', 'ddi', 4 3, '英语'
将学生表、课程表合成一个新表 desttb:
id 姓名 课程号 课程名
1 xix 1 语文
2 cic 2 数学
3 ddi null null
null null 3 英语
create table student(id nvarchar(10),name nvarchar(10),cno int)
insert student select '1','xix',1
union all select '2','cic',2
union all select '3','ddi',4
go
create table class(cno int,name nvarchar(10))
insert class select 1,'语文'
union all select 2,'数学'
union all select 3,'英语'
go
select id ,s.name as 姓名,c.cno as cno,c.name as 课程 from student as sclass as c s.cno=c.cno
-- ,结果集作为tmp
( as tmp
--如果目标表
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product