table a(id) table b(id)
id id
1 3
2 4
5想要得到如下
id1 id2
1 3
2 4
null 5
id id
1 3
2 4
5想要得到如下
id1 id2
1 3
2 4
null 5
解决方案 »
- sp_spaceused的问题?
- WINFROM中碰到了条SQL语句写不下去
- 有比sql2000自带的管理工具好点的工具软件么??
- reporting service 和 存储过程
- Excel 计算问题 -绿箭头
- 如何提高查詢的速度?
- 一个按标识求总和但是要无标识也要返回空值的SQL语句问题,大家快帮帮忙啊!
- SQL移除字符串问题
- sqlserver2005 访问sqlserver2000报错:用户 '(null)' 登录失败。原因: 未与信任 SQL Server 连接相关联。
- 如何从一台机器将整个数据库导出到另一台机器
- 一个简单的sql(insert)语句
- excel或dbf导入mssql时的问题
declare @tb table(id int)
insert @ta
select 1 union all
select 2
insert @tb
select 3 union all
select 4 union all
select 5----查询(注意:每个表的id必须是递增的)
select a.id,b.id from @tb as b left join @ta as a
on (select count(*) from @ta where id < a.id) = (select count(*) from @tb where id < b.id)/*结果
id id
----------- -----------
1 3
2 4
NULL 5
*/
select * from #a a
right join
#b b
on b.id-a.id=2
a ON b.id - a.id = 2
from
(select row_number() over (order by id) as Recn,* from t1) as a
left outer join
(select row_number() over (order by id) as Recn,* from t2) as b
on a.recn=b.recn
on (select count(*) from @ta where id < a.id) = (select count(*) from @tb where id < b.id) 这么牛鼻的 条件你 都 想得出来 ,真牛鼻