是这样吗:--drop table a,bcreate table a(id1 int,id2 int)insert into a
select 1 ,2 union all
select 2 ,3 union all
select 3 ,4create table b(id int,v varchar(10))insert into b
select 1 ,'a' union all
select 2 ,'b' union all
select 3 ,'c' union all
select 4 ,'d'
goselect b1.v,b2.v
from a
left join b b1
on b1.id = a.id1
left join b b2
on b2.id = a.id2
/*
v v
a b
b c
c d
*/
select 1 ,2 union all
select 2 ,3 union all
select 3 ,4create table b(id int,v varchar(10))insert into b
select 1 ,'a' union all
select 2 ,'b' union all
select 3 ,'c' union all
select 4 ,'d'
goselect b1.v,b2.v
from a
left join b b1
on b1.id = a.id1
left join b b2
on b2.id = a.id2
/*
v v
a b
b c
c d
*/
解决方案 »
- 谁有取汉字拼音的sql函数?
- ------------------------从Excel导入数据部分数据变成Null的问题。加了IMEX=1又报其它的错-----------------
- 在函数中调用自定义存储过程和getdate时出错
- 关于sql2000中用户权限的问题!
- 将原程数据库数据导入到本地Access中,来者有分
- 求一个SQL语句能实现如下查询,高手来解题!!!
- 用触发器生成消息队列
- 大数据量的系统的数据库结构如何设计?
- 如何删除数据库存在的对象--急急急急--在线等待
- 关于SQL SERVER2000底下数据库打开出现 “无项目” 的错误的问题
- 将原有数据库中表结构存储过程 导入到空数据库中
- 求2张表的差集,这个sql怎么写?
from a
inner join b b1
on b1.id = a.id1
inner join b b2
on b2.id = a.id2
select (select v from b where id= id1 ) , (select v from b where id= id2 ) from a
create table a(a1 int,a2 int)insert a select 1,2
union all
select 2,3
union all
select 3,4
create table b(b1 int,b2 varchar(30))insert into b select 1,'a'
union all
select 2,'b'
union all
select 3,'c'
union all
select 4,'d'
select (select b2 from b where b1=a1),(select b2 from b where b1=a2 ) from a