【问题标题】:How in SQL (Redshift) to select with IF condition?如何在 SQL (Redshift) 中使用 IF 条件进行选择?
【发布时间】:2020-03-28 15:13:32
【问题描述】:

我有一个 5 列的表。 Column1 的值为 'A'、'B'、'C' 和 'D',另一个 column2 的 int 值从 0 到 20,column3、column4 和 column5 有其他值,暂时不重要。

我想选择表中的所有记录,但不选择 column1 值“B”中的记录。但是,colum1 值为“B”的记录应满足 column2 中的值 > 10 的条件。如果它们在 column2 中为 ex。 15,我们可以将它们包含在选择中。

如何选择这个?

SELECT 
column1
, column2
, column3
, column4
, column5 

FROM tableA

WHERE 
only_include_values_B_from_column1_IF_it_has_in_column2_value_superior_than_10

【问题讨论】:

  • 样本数据和期望的结果会有所帮助。你的解释很混乱。

标签: sql amazon-redshift


【解决方案1】:

如果我理解正确,你想要OR:

SELECT column1, column2, column3, column4, column5 
FROM tableA a
WHERE column1 <> 'B' OR column2 > 10

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    相关资源
    最近更新 更多