我最近使此線程管理數據庫中的iPhone模型,以便能夠通過排除最後一個詞(這是容量)來選擇所有不同的模型, 。使用%LIKE%子句選擇並排除包含某些詞的結果
Select distinct first words of a field
+-----------+--------------------------------+
| id | model |
+-----------+--------------------------------+
| 1 | Apple iPhone 4S 16Gb |
| 2 | Apple iPhone 4S 32Gb |
| 3 | Apple iPhone 4 8Gb |
| 4 | Apple iPhone 6 Plus 32Gb |
| 5 | Apple iPhone 6 Plus 64Gb |
| 6 | Apple iPhone 6 16Gb |
+-----------+--------------------------------+
對於這個表,我有以下的輸出:
蘋果iPhone 4S
蘋果iPhone 4
蘋果iPhone 6加
蘋果iPhone 6
現在,我希望能夠爲每個模型獲得可用的容量領帶。 我想使用的LIKE %%條款,
SELECT * FROM `model` WHERE `value_model` LIKE '%Apple iPhone 6S%'
這是工作,直到模型與「加號」出現了。 爲iPhone 4S的爲例我必須做到以下幾點:
SELECT * FROM `model` WHERE `value_model` LIKE '%Apple iPhone 4S%'
我有這個輸入:
蘋果iPhone 4S 16GB的
蘋果iPhone 4S 32G的
但對於iPhone 6,它還將在我的結果中包含iPhone 6 Plus。
我怎麼能碰到這個,通過排除結果與'加',但也能夠不排除這個'加',當我要求一個'加'模型。
預先感謝您的:-)
你能寫出輸出的完美解決方案您正在尋找 ? – Imanez
只需獲得給定模型的結果。 對於iPhone 4S: 蘋果iPhone 4S 16GB,蘋果iPhone 4S 32G的 對於iPhone 6: 蘋果iPhone 6的16Gb – saperlipopette