问题不确切。这就是我的意思。
我有这个:
f0 | f1 | f2
------------
1 | 4 | a
1 | 4 | b
1 | 4 | c
2 | 6 | d
2 | 6 | e
2 | 6 | f
我需要这个:
f0 | f1 | f2_1 | f2_2 | f2_3 |
------------------------------
1 | 4 | a | b | c |
2 | 6 | d | e | f |
答案 0 :(得分:1)
尝试这样的事情:
select t1.f0, t1.f1, t3.f2 as a, t2.f2 as b, t1.f2 as c
from t1 t1
inner join t1 t2 on t1.f1 = t2.f1 and t1.f2 != t2.f2
inner join t1 t3 on t2.f1 = t3.f1 and t2.f2 != t3.f2
and t1.f2 != t3.f2
group by t1.f0, t1.f1;
<强> Example.. 强>