--要求连起来为a,b,c,d,记录数20条,c、d列缺少的记录用null补上。select id=identity(int,1,1),a,b into #t1 from m select id=identity(int,1,1),c,d into #t2 from n select a,b,c,d from #t1 a full join #t2 b on a.id=b.id drop table #t1,#t2
select id=identity(int,1,1),price,icount into #t1 from mselect a.id,a.price,a.icound,b.price,b.icount,c.price,c.icount from #t1 a join #t1 b on a.id=b.id-1 join #t1 c on a.id=c.id-2 where a.id%3=1
select id=identity(int,1,1),c,d into #t2 from n
select a,b,c,d from #t1 a full join #t2 b on a.id=b.id
drop table #t1,#t2
===========================
这句和前面的意思一样,只不过m,n为同一个表了。必须用临时表,一条语句写不出来吗?m表有price,icount两列,2000多行,
我想显示成price,icount,price,icount,price,icount六列的形式,记录数就变成700多了
====================================
m表有price,icount两列,2000多行,
我想显示成price,icount,price,icount,price,icount六列的形式,记录数就变成700多了
======================================
我假想成三个表了,看用一条语句能不能实现。
这么说两个表间没有条件是不能实现连接了,OK!谢谢各位!
from #t1 a join #t1 b on a.id=b.id-1
join #t1 c on a.id=c.id-2
where a.id%3=1
price icount
50 3
30 2
40 5
.......--2000多行---------------这样吧,你看CSDN文档中心有JSS一篇文章,专门讲这个的