MySQL 有赞的案例
MySQL CASE with 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
我做错了什么?
你少了一个逗号,像这样
setinfo,
CASE WHEN .. END
我的 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
我做错了什么?
你少了一个逗号,像这样
setinfo,
CASE WHEN .. END