【问题标题】:Choosing the name of a column when creating a view in Redshift在 Redshift 中创建视图时选择列的名称
【发布时间】:2021-06-16 13:30:47
【问题描述】:

我正在尝试创建一个视图,其中包含一个带有代码列表的列。这是我目前拥有的 SQL 代码:

DROP VIEW IF EXISTS myview;
CREATE OR REPLACE VIEW myview as
SELECT 'code1'
UNION
SELECT 'code2'
UNION
SELECT 'code3'

这将创建一个包含此列的视图:

?column?
code1
code2
code3

如您所见,列名是“?column?”我想将其更改为我选择的名称。我试过查看Redshift documentation,它说您可以指定列名,但我不确定什么是正确的语法,因为它们没有给出任何示例。

【问题讨论】:

    标签: sql database view amazon-redshift


    【解决方案1】:

    只需添加一个具有列名称的别名

    CREATE OR REPLACE VIEW logs.myview as
    SELECT 'code1' as my_column
    UNION
    SELECT 'code2'
    UNION
    SELECT 'code3';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 2018-03-14
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多