34,590
社区成员
发帖
与我相关
我的任务
分享
create table tb1(id int,cola int,othercol varchar(10))
insert into tb1 select 4,7,'fasd'
insert into tb1 select 7,5,'fwe'
create table tb2(id int,colb varchar(10),othercol varchar(10))
insert into tb2 select 3,'as','vwe'
insert into tb2 select 5,'mnivw','fwe'
--设两表都由id列排序:
select t1.cola,t2.colb from
(select cola,(select count(*) from tb1 where id<=a.id) as id0 from tb1 a)t1 inner join
(select colb,(select count(*) from tb2 where id<=b.id) as id0 from tb2 b)t2
on t1.id0=t2.id0
go
drop table tb1,tb2
/*
cola colb
----------- ----------
7 as
5 mnivw
(2 行受影响)
*/
select * from ta
union all
select * from tb
union all
select * from tc