options_table
options_id | object_id | option_value
=========================================
1 | 1 | drink
2 | 2 | ice
3 | 1 | bath
4 | 2 | soda
5 | 2 | drink
6 | 3 | ice
7 | 4 | bath
8 | 2 | bath
9 | 1 | storm
object_table
object_id | object_name
=============================
1 | sun
2 | moon
3 | mars
4 | jupiter
SELECT object_table.object_name GROUP_CONCAT(options_table.option_value) as object_options
FROM options_table
LEFT JOIN object_table
ON object_table.object_id = options_table.object_id
GROUP BY options_table.object_id
,所以我得到的結果一樣
object_name | object_options
=========================================
moon | ice, soda, drink, bath
sun | drink, bath, storm
mars | ice
jupiter | bath
比方說,用戶希望有選擇「喝」的所有對象和選項「洗澡」。所以我只得到這個結果。
object_name | object_options
=========================================
moon | ice, soda, drink, bath
sun | drink, bath, storm
如何編輯查詢以獲得此結果?
你能說'WHERE '喝' 的object_options AND '浴' IN object_options'? – 2012-08-07 12:28:25
當試圖在WHERE – Frankey 2012-08-07 12:34:20