--> 测试数据: @T1
declare @T1 table (id int,scode varchar(9),sqty int)
insert into @T1
select 1,'s1' ,1 union all
select 2,'s2' ,2
--> 测试数据: @T2
declare @T2 table (id int,pcode varchar(9),pqty int,yid int)
insert into @T2
select 12,'p2',3,2 union all
select 13,'p3',4,2
--> 测试数据: @T3
declare @T3 table (rcode varchar(9),rqty int,yid int)
insert into @T3
select 'r4',34,13 union all
select 'r5',35,13 union all
select 'r6',36,13select * from t1
left join t2
on t2.yid=t1.id
left join t3
on t3.yid=t2.id如何将结果集中t1,t2中的重复数据去掉,谢谢!
declare @T1 table (id int,scode varchar(9),sqty int)
insert into @T1
select 1,'s1' ,1 union all
select 2,'s2' ,2
--> 测试数据: @T2
declare @T2 table (id int,pcode varchar(9),pqty int,yid int)
insert into @T2
select 12,'p2',3,2 union all
select 13,'p3',4,2
--> 测试数据: @T3
declare @T3 table (rcode varchar(9),rqty int,yid int)
insert into @T3
select 'r4',34,13 union all
select 'r5',35,13 union all
select 'r6',36,13select * from t1
left join t2
on t2.yid=t1.id
left join t3
on t3.yid=t2.id如何将结果集中t1,t2中的重复数据去掉,谢谢!
解决方案 »
- 那里有好的 sql server 2005 啊 多谢各位了
- 计算机运行速度慢是什么原因
- 为什么不能用啊?关于取数据库表最后一条记录的问题!
- sql触发器:A表与B表的结构完全相同,把A表的增删改操作全都反映到B表中,即结果要求B表是A表的一个副本
- 潇洒老乌龟 你很帅,再出来一下
- 这sql语句有什么错哦 。。。。
- 新年快乐!想实现如下的累加统计,请问语句该如何写,愚昧我好几天了!
- 小论备份与恢复
- 问题1:创建一个与表student具有相同结构的表student2,并且
- 求救优化SQL
- 还是行列转的问题,如何用povit转两个列?
- =========== tsql操作xml,盼高手解答 ============
结果集贴不明白
with t
as(
select * from t2 a
inner join t3 b
on a.id=b.yid
)
select * from t1 a
inner join t2 b
on a.id=b.yid
left join t2
on t2.yid=t1.id
left join t3
on t3.yid=t2.id
这个就是我想要的结果,但是想把这个结果集里边,T1,T2重复的数据用NULL,替换掉
测试数据就是t1,t2,t3
关联关系
on t2.yid=t1.id
on t3.yid=t2.id1 s1 1 NULL NULL NULL NULL NULL NULL NULL
2 s1 2 2 p2 12 12 NULL NULL NULL
2 s1 2 2 p3 13 13 13 r6 36
2 s1 2 2 p3 13 13 13 r4 34
2 s1 2 2 p3 13 13 13 r5 35 这结果中的,重复数据用null替换,
2 s1 2 2 p2 12 12 NULL NULL NULL
p3 13 13 13 r6 36
r4 34
r5 35要这个样子