日期:2014-05-16 浏览次数:20463 次
--> 测试数据: [student]
if object_id('[student]') is not null drop table [student]
create table [student] (stuID int,stuName varchar(4))
insert into [student]
select 1,'张三' union all
select 2,'李四'
--> 测试数据: [origin]
if object_id('[origin]') is not null drop table [origin]
create table [origin] (oriID int,oriName varchar(4))
insert into [origin]
select 1,'本地' union all
select 2,'外地'
select * from [student]
select * from [origin]
SELECT A.stuid,A.stuname,b.oriID,b.oriname
FROM [student] A
LEFT JOIN [origin] B ON 1=1
/*
stuid stuname oriID oriname
1 张三 1 本地
1 张三 2 外地
2 李四 1 本地
2 李四 2 外地*/
--> 测试数据: [student]
if object_id('[student]') is not null drop table [student]
create table [student] (stuID int,stuName varchar(4))
insert into [student]
select 1,'张三' union all
select 2,'李四'
--> 测试数据: [origin]
if object_id('[origin]') is not null drop table [origin]
create table [origin] (oriID int,oriName varchar(4))
insert into [origin]
select 1,'本地' union all
select 2,'外地'
select * from [student]
select * from [origin]
SELECT A.stuid,A.stuname,b.oriID,b.oriname
FROM [student] A CROSS JOIN [origin] B