开发者

MySQL data in column wise which is stored in row based

I am having a table with data stored in row basis as shown below.

UID | DetailsID | Data|
----------------------|
 1  |     1     |  A  |
 1  |     2     |  200|
 1  |     3     |  2010-10-11 08:32 |
 2  |     1     |  B  |
 2  |     2     |  600|
 2  |     3     |  2011-05-20 14:56 |

From this I nee开发者_开发百科d the output as follows

UID|1|2|3
------------
1|A|200|2010-10-11 08:32
2|B|600|2011-05-20 14:56

Here main thing is, the number of entries of DetailsID values is not known.

I wanted this one in MySQL.

Please help me out of this.


Not quite what you want, but other than loads of left joins i can only suggest:

SELECT UID,GROUP_CONCAT(DetailsID SEPARATOR ",") "DetailsIDs",GROUP_CONCAT(Data SEPARATOR ",") "Data" FROM data_table GROUP BY UID;


Do that transformation in your coding language, not in SQL.


you didnt say where you need the output. If you need the output in PHP pages it is simple only by creating the loop for the entries in columns wise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜