我正在尝试在 mySQL 的 IF 子句中使用 LIKE 并收到错误。
SELECT nc.web_name AS company_name,
IF((b.booth_number LIKE '%Cafe%', b.booth_number, substring(b.booth_number,4)) AS booth_number,
nc.site_url AS website, IF (nc.ismi_status = 1, 'Member','') AS member_status
FROM booth_sale bs JOIN {ismi.booth} b ON bs.booth_id = b.booth_id
JOIN ismi.new_people np ON bs.contact_id = np.id
JOIN ismi.new_company nc ON nc.id = np.company_id
WHERE b.show_event_id = 298 AND status IN(44,45) ORDER BY 3
如果我这样做,查询工作正常:
IF((b.booth_number = 'Cafe', b.booth_number, substring(b.booth_number,4)) AS booth_number
但我需要检查多种可能性 - 可能有 Cafe、Cafe1、Cafe2 等,我想返回b.booth_number
该字段值包括 Cafe 的任何记录。
这是我得到的错误:
PDOException: SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 2 行的 'AS stand_number, nc.site_url AS website, IF (nc.ismi_status = 1, 'Member','') ' 附近使用:SELECT nc. web_name AS company_name, IF((b.booth_number LIKE '%Cafe%', b.booth_number, substring(b.booth_number,4)) ASbooth_number, nc.site_url AS 网站, IF (nc.ismi_status = 1, 'Member' ,'') AS member_status FROM {ismi.booth_sale} bs JOIN {ismi.booth} b ON bs.booth_id = b.booth_id JOIN {ismi.new_people} np ON bs.contact_id = np.id JOIN {ismi.new_company} nc ON nc.id = np.company_id WHERE b.show_event_id = 298 AND status IN(44,45) ORDER BY 3
谁能告诉我我做错了什么,或者是否有其他方法可以做到这一点?