MySQL CASE与LIKE

时间:2015-04-06 21:16:26

标签: mysql sql case sql-like

我的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

我做错了什么?

1 个答案:

答案 0 :(得分:5)

您缺少逗号,例如

setinfo,
CASE WHEN .. END