Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mysql中像在IF中一样使用_Mysql_Sql Like - Fatal编程技术网

在mysql中像在IF中一样使用

在mysql中像在IF中一样使用,mysql,sql-like,Mysql,Sql Like,我试图在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

我试图在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\u number
,用于该字段值包含Cafe的任何记录

这是我得到的错误:

PDOException:SQLSTATE[42000]:语法错误或访问冲突:1064 您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 如果(nc.ismi\U状态=1),则靠近“作为展位号,nc.site\U url作为网站”, 第2行的“成员”、“成员”:选择nc.web\u名称作为公司名称, 如果((b.展位号,如“%Cafe%”,b.展位号, 子字符串(b.展位号,4))作为展位号,nc.站点url作为网站, 如果(nc.ismi_status=1,'成员','')作为来自 {ismi.booth_sale}bs在bs.booth_id=b.booth_id上加入{ismi.booth}b 在bs.contact_id=np.id JOIN上加入{ismi.new_people}np {ismi.new_company}nc ON nc.id=np.company_id其中b.show_event_id= 298和3的(44,45)顺序中的状态


有谁能告诉我我做错了什么,或者是否有其他方法可以做到这一点吗?

如果您的
语句有一个太多的左括号。删除第一个,您应该是好的(当然,等待任何其他SQL错误):


您的
IF
语句有一个太多的左括号。删除第一个,您应该会很好(当然,等待任何其他SQL错误):


新家具很好的捕捉。我想指出,拥有
booth\u number
别名到
booth\u number
可能有点风险。区分可能会有帮助。这是一个很好的观点。我继承了这个代码,而且它很有效,所以我没有摆弄它。但我会在代码中做一个注释。新家具很好的捕捉。我想int out使用
booth_number
别名作为
booth_number
可能有点风险。区分可能会有帮助。这是一个好的观点。我继承了这个代码,它正在工作,所以我没有摆弄它。但我会在代码中记下这样做的方法。谢谢!我本来以为只有两个可能的值,所以我有一个或者在IF内;我想我在清理时错过了一个开始部分。谢谢!我本来以为只有两个可能的值,所以我在IF内有一个OR;我想我在清理时错过了一个开始部分。
...
IF(b.booth_number LIKE '%Cafe%', b.booth_number, substring(b.booth_number,4)) AS booth_number, 
...