可能重複:
mysql converting multiple rows into columns in a single row的mysql組由多行
我有一個MySQL表是這樣的:
id | p | c | v
1 p1 10 1
2 p1 20 2
3 p1 30 3
4 p2 40 1
5 p2 50 2
6 p2 60 3
現在我需要運行一個SQL並得到像這樣的結果:
p | as_c1 | as_c2 | as_c3
p1 10 20 30
p2 40 50 60
我用這個查詢,但還遠遠不夠:
select
p,
c as as_c1,
c as as_c2,
c as as_c3
from test_tbl group by p, c
我找遍了那裏,這可能嗎?我只需要一些指導。
非常感謝您的大力幫助。 – Vahid
爲什麼我得到#1243 - 未知的預處理語句處理程序(stmt)在本地主機phpmyadmin中運行動態方式時給予EXECUTE?有人在這裏說:http://stackoverflow.com/questions/12270953/combine-multiple-rows-into-one-mysql,但我不明白他做了什麼。 – Vahid