代码之家  ›  专栏  ›  技术社区  ›  Fhd.ashraf

where子句中的多种情况条件

  •  1
  • Fhd.ashraf  · 技术社区  · 7 年前

    我有一张有两列的桌子。一层和二层。现在f1有id,f2有得分。

    F1 Score
    1   10
    1   20
    6   10
    

    现在我想要一个where子句,它将6看作1,并将它们与1相加

    例如,当我使用f1=1时,它应该给出

     F1 Score
        1   10
        1   20
        1   10
    

    我用过

    式中(f1=当f1=6时,则为1,否则为f1结束)

    但不起作用。

    2 回复  |  直到 7 年前
        1
  •  0
  •   Gordon Linoff    7 年前

    你似乎想要:

    select (case when f1 = 6 then 1 else f1 end) as new_f1,
           score
    from t
    order by new_f1;
    

    编辑:

    你改变了问题。对于过滤,您只需执行以下操作:

    where f1 in (1, 6)
    
        2
  •  0
  •   Nedzad G    7 年前

    试试这个:

    select (case when F1 = 6 then 1 else F1 end) as something, SCORE 
    from your_table