我試圖進入這一問題儘可能明確合併兩個領域進入第一場,其中的product_id是相同的,attribute_id是53或54
在MySQL中我有一個表oc_product_attribute
我有表看起來像這樣
-------------------------------
|product_id|attribute_id|text |
-------------------------------
|2125 |53 |text1|
|2125 |54 |text2|
|2356 |53 |text3|
|2356 |54 |text4|
-------------------------------
我想擺脫attribute_id 54和在這一領域的文本用逗號作爲分隔符追加到文本attribute_id 53。
所以basicly看起來像這樣:
--------------------------------------
|product_id|attribute_id|text |
--------------------------------------
|2125 |53 |text1, text2|
|2356 |53 |text3, text4|
--------------------------------------
我也有其他的attribute_is的,我不希望改變。
任何人都知道如何?
你想展示你做了什麼至今... – SubjectDelta
https://dev.mysql.com/doc/refman/5.7/en/group- by-functions.html#function_group-concat – SubjectDelta
使用case語句將54更改爲53'case when attribute_ID = 54 then 53 else attribute_ID end as Attribute_ID'然後使用'group_concat()'將文本與一個group在product_ID和attribute_ID上。但是您沒有指定是否希望將其作爲表更改或查詢。另外,如果表格變化,我認爲你會走錯路。因爲您現在在單個字段中具有多個值,這在數據庫設計中是不允許的。 – xQbert