case statement in SQL, how to return multiple variables?

后端 未结 9 2193
甜味超标
甜味超标 2020-12-05 13:40

I would like to return multiple values in my case statement, such as :

SELECT
  CASE
    WHEN  THEN 
    WHEN          


        
9条回答
  •  没有蜡笔的小新
    2020-12-05 14:17

    You could use a subselect combined with a UNION. Whenever you can return the same fields for more than one condition use OR with the parenthesis as in this example:

    SELECT * FROM
      (SELECT val1, val2 FROM table1 WHERE (condition1 is true) 
                                        OR (condition2 is true))
    UNION
    SELECT * FROM
      (SELECT val5, val6 FROM table7 WHERE (condition9 is true) 
                                        OR (condition4 is true))
    

提交回复
热议问题