SQL IF ELSE STATEMENT

时间:2016-07-08 03:55:43

标签: mysql sql

1. SELECT ORDER
FROM ORDERLIST
WHERE IsCompleted='Y'

2. SELECT ORDER
FROM ORDERLIST
WHERE IsCompleted='N'

然后输出是' NULL'

我想整合这两个逻辑,但我不知道如何使代码工作。请帮帮我!

3 个答案:

答案 0 :(得分:2)

试试这个......

您可以使用CASE WHEN表达式

SELECT 
    CASE
        WHEN IsCompleted='Y' 
        THEN
            [ORDER]
        ELSE WHEN IsCompleted='N' 
        THEN
           NULL
    END 
FROM 
    ORDERLIST 

答案 1 :(得分:0)

'分类:G642.44'如UNION?:

SELECT ORDER
FROM ORDERLIST
WHERE IsCompleted='Y'
UNION
SELECT NULL
FROM ORDERLIST
WHERE IsCompleted='N'

答案 2 :(得分:0)

试试这个,这应该可以让你在一个表中得到所有结果。

    SELECT ORDER
    FROM ORDERLIST
    WHERE IsCompleted = 'Y' OR IsCompleted = 'N'