表结构为:
F1 F2
a a1
b b1
c c1
a a3
a a4
b b2
c c2
c c3
.......
想要的结果为:
F1 F2 F3 F4 F5.....(最多15个),列名随意。
a a1 a2 a3 a4
b b1 b2
c c1 c2 c3
....就是把Table中的按照F1的名字,把F2的不超过15个的内容依次列出。最好直接用SQL语句,不使用函数、临时表等。
F1 F2
a a1
b b1
c c1
a a3
a a4
b b2
c c2
c c3
.......
想要的结果为:
F1 F2 F3 F4 F5.....(最多15个),列名随意。
a a1 a2 a3 a4
b b1 b2
c c1 c2 c3
....就是把Table中的按照F1的名字,把F2的不超过15个的内容依次列出。最好直接用SQL语句,不使用函数、临时表等。
max(case px when 1 then f2 else '' end) t1,
max(case px when 2 then f2 else '' end) t2,
...
max(case px when 15 then f2 else '' end) t15
from
(
select t.* , px = (select count(1) from tb where f1 = t.f1 and f2 < t.f2) + 1 from tb t
) m
group by f1