我们应该使用什么查询将1colmnn拆分为多列

时间:2011-04-08 10:20:37

标签: mysql

Table name-userdb
id |  name  |  value
1  | fname   | anand
1  | lname   | kumar
1  |city     | bangalore
2  |fname    |mahesh
2  |lname    |sahoo
2  |city     |manglore
3  |fname    |anil
3  |lname    |singh
3  |city     |balasore

我需要显示

fname  |  lname  |  city
anand  |  kumar  | bangalore
mahesh | sahoo   | manglore
anil   |singh    |balasore

为此请给我mysql查询

1 个答案:

答案 0 :(得分:0)

mmm .. EAVS ......除了实际实现设计的明显建议之外,你可以实现你想要的:

Select Min( Case When name = 'fname' Then value End ) As fname
    , Min( Case When name = 'lname' Then value End ) As lname
    , Min( Case When name = 'city' Then value End ) As city
From MyTable
Group By Id