How to create virtual column using MySQL SELECT?

前端 未结 6 1918
天命终不由人
天命终不由人 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 14:01

    You can add virtual columns as

    SELECT '1' as temp
    

    But if you tries to put where condition to additionally generated column, it wont work and will show an error message as the column doesn't exist.

    We can solve this issue by returning sql result as a table.ie,

    SELECT tb.* from (SELECT 1 as temp) as tb WHERE tb.temp = 1
    

提交回复
热议问题