首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用case语句创建视图?

如何使用case语句创建视图?
EN

Stack Overflow用户
提问于 2021-02-14 09:00:29
回答 1查看 34关注 0票数 0

我有一个表"hallowelt“,它包含15列,其中一列的名称是"month”。如何创建表"hallowelt“的视图,其中月份通过CASE语句适当地转换为新的列季节,分为春、夏、秋、冬。

示例代码:

代码语言:javascript
运行
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-14 12:57:47

你可能想要像这样的东西

代码语言:javascript
运行
复制
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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66191485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档