如何使用 case 语句创建视图?
How to create a view with case statement?
我有一个 table“hallowelt”,它包含 15 列,其中一列名称是“month”。
如何创建 table“hallowelt”的视图,其中月份通过 CASE 语句适当地转换为新列 SEASON 到 spring、夏季、秋季和冬季。
示例代码:
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;
我有一个 table“hallowelt”,它包含 15 列,其中一列名称是“month”。 如何创建 table“hallowelt”的视图,其中月份通过 CASE 语句适当地转换为新列 SEASON 到 spring、夏季、秋季和冬季。
示例代码:
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;