简体   繁体   English

mySQL 案例 那么<something>别的<dont select></dont></something>

[英]mySQL CASE THEN <something> ELSE <dont select>

I'm using mySQL query together with CASE statement in the WHERE clause.我在 WHERE 子句中使用 mySQL 查询和 CASE 语句。

SELECT * from places WHERE 
                        CASE WHEN
                            column1 > column2
                        THEN 
                            id > 100
                        WHEN 
                            column1 < column2
                        THEN
                            id < 100
                         ELSE
                            <DONT SELECT THE ROW>
                         END

I'm not sure how to Not select any rows if column1 = column2 (meaning we are in the ELSE branch).如果 column1 = column2 (意味着我们在 ELSE 分支中),我不确定如何 Not select 任何行。 How should I achieve this?我应该如何实现这一目标?

SELECT * from places WHERE 
                    CASE WHEN
                        column1 > column2
                    THEN 
                        id > 100
                    WHEN 
                        column1 < column2
                    THEN
                        id < 100
                    END
AND column1 != column2

Try add impossible condition ELSE 0 = 1 .尝试添加不可能的条件ELSE 0 = 1 Another option I'm not 100% sure is not to put anything in ELSE - it must have default ELSE NULL我不是 100% 确定的另一个选项是不要在ELSE中添加任何内容 - 它必须具有默认的ELSE NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM