table1: 字段为
ID1,ID2,ID3,ID4table2: 字段为
ID,Nameselect b.name,c.name,d.name,e.name from table1 a left join table2 b
on a.id1=b.id
left join table2 c
on c.id2=b.id
left join table2 d
on d.id3=b.id
left join table2 e
on e.id4=b.id
ID1,ID2,ID3,ID4table2: 字段为
ID,Nameselect b.name,c.name,d.name,e.name from table1 a left join table2 b
on a.id1=b.id
left join table2 c
on c.id2=b.id
left join table2 d
on d.id3=b.id
left join table2 e
on e.id4=b.id
解决方案 »
- 100分求一个比较难的SQl 语句. (最好能在VF中实现)
- 问一个小sql问题?在线等待
- 哪位帮我看看我这个游标什么地方有错么?
- 有关sql server 2005 相关过程、函数等发布
- 请问 real类型数据如何取啊,各位兄弟帮帮忙啊?
- 如何把字段为空的信息给查出来?
- 请教时间查询的sql问题???
- ?我的机器是Win2000专业版,现在想装SQL2000,能注册本地的实例,并且在本地建数据库,应该装哪一个版本的啊??谢谢!急!(
- 一个比较麻烦的SQLServer存储过程问题,不知道怎么说,请进来看下吧
- 有这么一个需求,怎样来写sql
- 请教高手把两个表合并的写法
- 怎样用bcp把数据导入到远程服务器?
set table1.id1=table2.name
from table2
where table1.id1=table2.id
不行就建立一个新表吧
insert into newtable(id1_name)
select b.name
from table1 as a,
table2 as b
where a.id1=b.id
(case a.ID1 when b.ID then b.name else null end) as ID2_Name,
(case a.ID1 when b.ID then b.name else null end) as ID3_Name,
(case a.ID1 when b.ID then b.name else null end) as ID4_Name
from table1 a,table2 b不过这样会出现很多的空数据
(select name from table1 where id=table1.id1) ID1_Name,
(select name from table1 where id=table1.id2) ID2_Name,
(select name from table1 where id=table1.id3) ID3_Name,
(select name from table1 where id=table1.id4) ID4_Name
from table1
,b.name ad ID2_Nametable1: 字段为
ID1,ID2,ID3,ID4table2: 字段为
ID,Name
select a.name as ID1_Name
,b.name as ID2_Name
,c.name as ID3_Name
,d.name as IDs_Name
from table1 left join table2 a on a.id=id1
left join table2 b on a.id=id2
left join table2 c on a.id=id3
left join table2 d on a.id=id4
return Varchar(200)
as
Return (select name From table2 where id=@id)goselect id1_name=searchname (id1),
id1_name=searchname (id2),
id1_name=searchname (id3),
id1_name=searchname (id4)
From table1
psxfghost(哈哈) 的方法挺有创意,效果不好,把ID顺序打乱每一条记录的对应列的名字和顺序都改变了pengdali(大力 V2.0) 的方法不可行,因为子查询里有多个记录的话,查询失败 lilu207(lilu) 的方法我也考虑过,建表不方便还是CrazyFor方法最好,谢谢了.