select identity(int,1,1)xh,* into #t from 表
select aa.c as a1,bb.c as b1,cc.c as c1
from #t aa left join #t b on aa.xh=bb.xh-1
left join #t cc on aa.xh=cc.xh-2
where (aa.xh-1)%3=0
select aa.c as a1,bb.c as b1,cc.c as c1
from #t aa left join #t b on aa.xh=bb.xh-1
left join #t cc on aa.xh=cc.xh-2
where (aa.xh-1)%3=0
select A.c as a1,B.c as b1,C.c as c1 from #t A left join #t b on A.idd=b.idd-1
left join #t C on A.idd=C.idd-2 where (a.idd-1)%3=0
b1=Max(Case when b='sex' then c else '' end)
c1=Max(Case when b='age' then c else ''end)
from 表 Group by a
b1=Max(Case when b='sex' then c else '' end),
c1=Max(Case when b='age' then c else ''end)
from 表 Group by a
(SELECT a as ID, CASE when b='name' then c end AS a1,
CASE when b='sex' then c end as b1,
CASE when b='age' then c end as c1
FROM 原始表) A --内部的临时表非常有用!!
GROUP BY A.ID
(SELECT a as ID, CASE when b='name' then c else '' end AS a1,
CASE when b='sex' then c else '' end as b1,
CASE when b='age' then c else '' end as c1
FROM 原始表) A --内部的临时表非常有用!!
GROUP BY A.ID
不经过内部表会出乱子的!!
max(case when b='name' then c end) a1,
max(case when b='sex' then c end) a2,
max(case when b='age' then c end) a3
from 表 group by a