错误时的SQL情况

时间:2014-02-19 10:27:36

标签: mysql sql

你好我的sql查询仍然返回else case但我很确定内部select返回1.代码有什么问题?

SELECT CASE a_from
WHEN (SELECT a_from REGEXP 'something.com>$' = 1 )
     THEN "S"
ELSE "T"
END AS 'HP', a_from FROM article WHERE id =4

2 个答案:

答案 0 :(得分:0)

你可能在内部选择

中缺少一个WHERE
(SELECT a_from REGEXP WHERE 'something.com>$' = 1 )

答案 1 :(得分:0)

我认为你错过了内部选择陈述中的where

SELECT CASE a_from
WHEN (SELECT a_from REGEXP where 'something.com>$' = 1 )  <-- Here 
     THEN "S"
ELSE "T"
END AS 'HP', a_from FROM article WHERE id =4

如ypercube所评论,您可以尝试这样:

SELECT CASE WHEN a_from REGEXP 'something.com>$' = 1 
 THEN 'S' 
ELSE 'T' END AS hp, a_from 
FROM article WHERE id = 4 ;