select u_id,
DD=case when u_name='d' then d end,
EE=case when u_name='e' then e end,
FF=case when u_name='f' then f end,
from xxx
where u_id=2
DD=case when u_name='d' then d end,
EE=case when u_name='e' then e end,
FF=case when u_name='f' then f end,
from xxx
where u_id=2
U_id,
(Select U_name from A Where U_name='d') As DD,
(Select U_name from A Where U_name='e') As EE,
(Select U_name from A Where U_name='f') As FF
from A
Where U_id=2
name as DD,
char(ascii(name)+1) as ee,
char(ascii(name)+2) as ff
from tb1
where id=4
insert into #tb select 1,1,'a'
insert into #tb select 2,1,'b'
insert into #tb select 3,1,'c'
insert into #tb select 4,2,'d'
insert into #tb select 5,2,'e'
insert into #tb select 6,2,'f'
insert into #tb select 7,3,'g'
insert into #tb select 8,3,'h'
insert into #tb select 9,3,'i'
select
a.U_id,
max(case cnt when 1 then b.U_name end) ,
max(case cnt when 2 then b.U_name end) ,
max(case cnt when 3 then b.U_name end)
from
#tb a,
(select c.*,cnt=count(d.id) from #tb c,#tb d where c.U_id=d.U_id and c.id>=d.id group by c.id,c.U_id,c.U_name) b
where
a.U_id =b.U_id
group by
a.U_id