有二个表Main_Sheet 如下
Sheet_Name Num Weight Rept
小王 1 2 20070101
小张 2 3 20070101
小李 12 24 20070101
小王 1 2 20070102
小张 4 1 20070102
小李 5 1 20070102
表Xb_Sheet如下
Sheet_Name Num Weight Rept
小邓 1 2 20070101
小邓 5 1 20070102
表Xb_Sheet表中只有Sheet_Name等于小邓的行数据,现在我要查询Rept等20070101的要求结果如下
Sheet_Name Num Weitht Rept
小王 1 2 20070101
小张 2 3 20070101
小李 12 24 20070101
小邓 1 2 20070101
我用Right join 无法得到结果,请问该怎么写语句,谢谢
Sheet_Name Num Weight Rept
小王 1 2 20070101
小张 2 3 20070101
小李 12 24 20070101
小王 1 2 20070102
小张 4 1 20070102
小李 5 1 20070102
表Xb_Sheet如下
Sheet_Name Num Weight Rept
小邓 1 2 20070101
小邓 5 1 20070102
表Xb_Sheet表中只有Sheet_Name等于小邓的行数据,现在我要查询Rept等20070101的要求结果如下
Sheet_Name Num Weitht Rept
小王 1 2 20070101
小张 2 3 20070101
小李 12 24 20070101
小邓 1 2 20070101
我用Right join 无法得到结果,请问该怎么写语句,谢谢
create table Main_Sheet(Sheet_Name varchar(10), Num int, Weight int, Rept varchar(10))
insert Main_Sheet select '小王',1,2,'20070101'
union all select '小张',2,3,'20070101'
union all select '小李',12,24,'20070101'
union all select '小王',1,2,'20070102'
union all select '小张',4,1,'20070102'
union all select '小李',5,1,'20070102'create table Xb_Sheet(Sheet_Name varchar(10), Num int, Weight int, Rept varchar(10))
insert Xb_Sheet select '小邓', 1, 2, '20070101'
union all select '小邓', 5, 1, '20070102'select * from Main_Sheet
where Sheet_Name='小邓'select * from
(
select * from Main_Sheet
union all
select * from Xb_Sheet
)tmp
where Rept='20070101'--result
Sheet_Name Num Weight Rept
---------- ----------- ----------- ----------
小王 1 2 20070101
小张 2 3 20070101
小李 12 24 20070101
小邓 1 2 20070101(4 row(s) affected)
create table Main_Sheet(Sheet_Name varchar(10), Num int, Weight int, Rept varchar(10))
insert Main_Sheet select '小王',1,2,'20070101'
union all select '小张',2,3,'20070101'
union all select '小李',12,24,'20070101'
union all select '小王',1,2,'20070102'
union all select '小张',4,1,'20070102'
union all select '小李',5,1,'20070102'create table Xb_Sheet(Sheet_Name varchar(10), Num int, Weight int, Rept varchar(10))
insert Xb_Sheet select '小邓', 1, 2, '20070101'
union all select '小邓', 5, 1, '20070102'select * from Main_Sheet
where Rept='20070101'
union all
select * from Xb_Sheet
where Rept='20070101'--result
Sheet_Name Num Weight Rept
---------- ----------- ----------- ----------
小王 1 2 20070101
小张 2 3 20070101
小李 12 24 20070101
小邓 1 2 20070101(4 row(s) affected)