【问题标题】:HSQL - Adding a new column in the query based on an IF conditionHSQL - 根据 IF 条件在查询中添加新列
【发布时间】:2021-08-31 04:30:46
【问题描述】:

我需要生成一列,在每一行中检查Bestand 是否小于、等于或大于Minbestand。如果是这样,名为Bestandsbewertung 的新列需要分别给出MangelMindestbestandÜberfluß

SELECT IF(Bestand < Minbestand, 'Mangel', IF(Bestand = MinBestand, 'Mindestbestand', 'Überstand')) AS Bestandsbewertung, Teile.*
FROM Teile

我试过这段代码,但 HSQL 说它不知道 IF

This is what the Table looks like if it helps

【问题讨论】:

    标签: sql hsqldb


    【解决方案1】:

    HSQL 似乎不接受IF。经过反复试验,我得出了这个问题的解决方案。

    SELECT Teile.*,
           CASE Bestand WHEN < MinBestand THEN 'Mangel'
                        WHEN = MinBestand THEN 'Mindestbestand'
                        WHEN > MinBestand THEN 'Überfluß' END AS Bestandsbewertung
    FROM Teile
    

    它似乎没有任何问题。

    【讨论】:

    • 也可以写成CASE Bestand WHEN &lt; MinBestand THEN 'Mangel' WHEN = MinBestand THEN 'Mindestbestand' WHEN &gt; MinBestand THEN 'Überfluß' END
    猜你喜欢
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    相关资源
    最近更新 更多