How to create virtual column using MySQL SELECT?

前端 未结 6 1921
天命终不由人
天命终不由人 2020-12-07 13:31

If I do SELECT a AS b and b is not a column in the table, would query create the \"virtual\" column?

in fact, I need to incorporate some virtual column into the quer

6条回答
  •  悲哀的现实
    2020-12-07 13:51

    You could use a CASE statement, like

    SELECT name
           ,address
           ,CASE WHEN a < b THEN '1' 
                 ELSE '2' END AS one_or_two
    FROM ...
    

提交回复
热议问题