CASE statement in SQLite query

后端 未结 2 1320
Happy的楠姐
Happy的楠姐 2021-02-01 13:30

Why this query doesn\'t work? :( I tried to replace nested IF statement \"...SET lkey = IF(lkey >= 11, lkey - 5, IF(lkey > 5, lkey + 2,lkey))\"

UPDATE pages
SET          


        
2条回答
  •  春和景丽
    2021-02-01 13:55

    The syntax is wrong in this clause (and similar ones)

        CASE lkey WHEN lkey > 5 THEN
            lkey + 2
        ELSE
            lkey
        END
    

    It's either

        CASE WHEN [condition] THEN [expression] ELSE [expression] END
    

    or

        CASE [expression] WHEN [value] THEN [expression] ELSE [expression] END
    

    So in your case it would read:

        CASE WHEN lkey > 5 THEN
            lkey + 2
        ELSE
            lkey
        END
    

    Check out the documentation (The CASE expression):

    http://www.sqlite.org/lang_expr.html

提交回复
热议问题