簡體   English   中英

從表WHERE`column` = x中選擇*如果`column`!= -1

[英]Select * from table WHERE `column` = x if `column` != -1

我需要做出選擇,

Select * from table WHERE column = x if column != -1

但我暫時不知道。

任何人都知道或做過這樣的事嗎?

謝謝。

你也應該這樣寫

Select * from table 
WHERE 
1 = case when column != -1 then 
        case when column = x then 1 else 0 end
    else 1 end

您可以在where子句中使用大小寫。 同樣,您可以添加更多條件條件,例如,

Select * from table 
WHERE 
1 = case when column != -1 then 
        case when column = x then 1 else 0 end
    else 1 end
AND 
1 = case when column1 [conditional operator] value then
        case when column1 = xx then 1 else 0 end
    else 1 end

這只是一個示例,您可以將更多的條件條件整合在一起,即使您可以在其他部分添加更多的情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM