MySQL纵表转换成横表
老问题了,在网上没有看到MySQL方面的转换方法,多是Oracle的。可惜差在MySQL比之Oracle函数功能差的太远,无法使用。
字段大概是这样的:
id   product_id product_count  sn
1    2              1                    1234
1    1              1                    1234
1    3              1                    1234
1    2              2                    4567
1    5              4                    4567
想变成
id   product_id1 product_count1   product_id2 product_count2  product_id3 product_count3
1    2                1                      1                1                     3                1
1    2                2                      5                4
问题最重要的是:列数不定,完全根据在同一个sn里面的记录数来的。
大家帮忙看下。
------解决方案--------------------
------解决方案--------------------http://topic.csdn.net/u/20110908/10/3f25297e-12c2-4ad6-b7df-6b6711a3f063.html
参考