奇怪的問題......我知道。所以讓我解釋一下。選擇查詢,總結行並將其作爲列返回
這裏是我的文字表
quota | metric_id
100 | 1
20 | 2
100 | 15
50 | 1
30 | 2
20 | 15
50 | 1
200 | 2
10 | 15
我想要的SELECT語句將返回以下
id_1 | id_2 | id_15
200 | 250 | 130
下面是數據是:
Column `id_1` is sum of the 3 rows where `metric_id=1`
Column `id_2` is sum of the 3 rows where `metric_id=2`
Column `id_15` is sum of the 3 rows where `metric_id=15`
任何幫助?
轉換'列'id_1'是3行的總和,其中'metric_id = 1''爲SQL,你很高興去。 – Shomz
[How to pivot a MySQL entity-attribute-value schema]可能的重複(http://stackoverflow.com/questions/649802/how-to-pivot-a-mysql-entity-attribute-value-schema) – Vatev
'metric_id'是靜態的嗎?只有這3個值? –