简体   繁体   English

如何在WHERE子句中将“ IN”与“ CASE语句”一起使用?

[英]How to use “IN” with “CASE Statement” in WHERE Clause?

Below is my MYSQL Query 以下是我的MYSQL查询

select * from `ordermaster` where OrderStatus in (case when 1= 0 then OrderStatus else ("Completed","Cancelled") end)

as you can see 1st condition is ALL and next condition is Specific. 如您所见,第一个条件是ALL,下一个条件是Specific。

if condition 1 is satisfied then I would like to return entire data wrt orderstatus but if condition is satisfied then I want only records whose OrderStatus is "Completed" OR "Cancelled" but this is giving issue. 如果满足条件1,则我想返回带有订单状态的整个数据,但是如果满足条件,则我只想要其OrderStatus为“已完成”或“已取消”的记录,但这给了问题。 I can directly use "IN" but cannot use with "CASE" statement. 我可以直接使用“ IN”,但不能与“ CASE”语句一起使用。

Thanks, Rahul 谢谢,拉胡尔

SELECT ordermaster
    CASE 
        WHEN OrderStatus = 1 THEN 'Completed'
        WHEN OrderStatus = 0 THEN 'Cancelled'
    END AS STATUS 
FROM ordermaster;

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

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