0

私はこのようなテーブルを持っています:

ユーザーID | フィッド | 価値
1 | 1 | nameOf1
1 | 2 | 姓1
1 | 3 | 国1
2 | 1 | nameOf2
2 | 2 | 姓の2

そして、次のように変換/選択する必要があります:

ユーザーID | 名前 | 姓 | 国
1 | nameOf1 | 姓の1 | 国1
2 | nameOf2 | 姓の2 | ..
4

2 に答える 2

0

少し複雑ですが、次のようなことができます。

select distinct uid as uid,
   (select value from dataTable as table1 
           where table1.uid=dataTable.uid and fid = 1) as name,
   (select value from dataTable as table2 
           where table2.uid=dataTable.uid and fid = 2) as surname,
   (select value from dataTable as table3 
           where table3.uid=dataTable.uid and fid = 3) as country
from dataTable group by uid

SQLフィドル

于 2013-11-17T15:35:19.667 に答える