日期:2014-05-18 浏览次数:20617 次
select a.*,b.tcontent as tcontent2 from tb a left join tb b on a.bz=b.id
------解决方案--------------------
select a.*,b.tcontent as tcontent2 from tb a left join tb b on a.bz=b.id
------解决方案--------------------
select t.* , (select tcontent from tb where bz = t.id) tcontent2 from tb t
------解决方案--------------------
create table tb(id int,tname varchar(20) , tcontent varchar(20) , bz int)
insert into tb values(1 ,'aa', '这是内容' ,null)
insert into tb values(2 ,'bb', '2的' ,1)
insert into tb values(3 ,'cc', '3的' ,1)
go
select t.* , (select tcontent from tb where id = t.bz) tcontent2 from tb t
drop table tb
/*
id tname tcontent bz tcontent2
----------- -------------------- -------------------- ----------- --------------------
1 aa 这是内容 NULL NULL
2 bb 2的 1 这是内容
3 cc 3的 1 这是内容
(所影响的行数为 3 行)
*/