SQL: Alias Column Name for Use in CASE Statement

前端 未结 11 1784
悲哀的现实
悲哀的现实 2020-12-04 21:38

Is it possible to alias a column name and then use that in a CASE statement? For example,

SELECT col1 as a, CASE WHEN a = \'test\' THEN \'yes\' END as value          


        
11条回答
  •  天命终不由人
    2020-12-04 22:01

    Not in MySQL. I tried it and I get the following error:

    ERROR 1054 (42S22): Unknown column 'a' in 'field list'

提交回复
热议问题