sql选择case作为

toiithl6  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(263)

我在写sql语句。看起来像这样

select case when c.used = 1 then 'Used'
            else 'Unused'
       end
from my_table

我怎样才能用 as 关键字。我试过了线和线之后 end . 什么都不管用。
请帮帮我。谢谢:)

gmxoilav

gmxoilav1#

您可以使用反勾号引用保留字:

select case when c.used = 1 then 'Used'
            else 'Unused'
       end AS `as`
from my_table;

可选使用 "" :

SELECT 1 AS `as`, 2 AS "as"

dbfiddle演示

相关问题