-2
我遇到了MySQL Query的問題,我正在使用案例來給它排序。訂單取決於序列號。與MySQL相似的案例
我的查詢是:
SELECT DISTINCT id, price, itemnr, itemnr_ori, link, name, setinfo
CASE WHEN itemnr_ori LIKE '%-%-s%' THEN 0 WHEN itemnr_ori LIKE 'z-%-%' THEN 1
WHEN itemnr_ori LIKE 'ak-%' THEN 2
WHEN itemnr_ori LIKE 'fdc-%' THEN 3
WHEN itemnr_ori LIKE 'max-%' THEN 4
ELSE 5 END
AS sort_order FROM items2 WHERE category1 = 'Overige' AND category2 = 'Afrikaanse Overige' ORDER BY sort_order ASC, price ASC, itemnr_ori ASC
我得到這個錯誤:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN itemnr_ori LIKE '%-%-s%' THEN 0 WHEN itemnr_ori LIKE 'z-%-%' THEN 1 WH' at line 1
我在做什麼錯?
如果你要花費與MySQL隨時習慣仔細閱讀錯誤消息 - 他們通常告訴你到底哪裏出錯你碼。在這種情況下,第一個錯誤是在CASE一詞,所以你可以看到你錯過了逗號。學會喜歡錯誤信息。 –