如何解决如何使用 case 语句创建视图?
我有一张“万圣节”表,其中包含 15 列,其中一个列名为“月”。 如何创建“万圣节”表的视图,其中月份通过 CASE 语句适当地转换为新列 SEASON 进入春季、夏季、秋季和冬季。
示例代码:
create view hallo_welt
SELECT month,as 'season'
CASE
when month=3 or month<=5 then 'Frühling'
when month=6 or month<=8 then 'sommer'
when month=9 or month<=11 then 'Herbst'
when month=12 or month<=2 then 'winter'
else ''
END
from hallowelt;
解决方法
你可能想要类似的东西
create view hallo_welt
SELECT
month,CASE
when month in (3,4,5) then 'Frühling'
when month in (6,7,8) then 'sommer'
when month in (9,10,11) then 'Herbst'
when month in (12,1,2) then 'winter'
else null
END season
from hallowelt;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。