【问题标题】:Fill null values from other column using Teradata SQL使用 Teradata SQL 从其他列填充空值
【发布时间】:2022-01-14 01:27:46
【问题描述】:

如何填写?还是 col2 中的 null 值与 col1 中的对应值使用 Teradata SQL?

数据

col1    col2 
10       10   
11       ?
12       12
14       ?
65       ?

预期输出

col1    col2 
10       10   
11       11
12       12
14       14
65       65

【问题讨论】:

    标签: sql teradata teradata-sql-assistant


    【解决方案1】:

    使用COALESCE:

    SELECT col1, COALESCE(col2, col1) AS col2
    FROM yourTable
    ORDER BY col1;
    

    【讨论】:

      【解决方案2】:
      select c.col1,
      case
        when c.col2 is null then c.col1
        else col2
      end as col2
      from your_table as c
      

      【讨论】:

        猜你喜欢
        • 2018-10-12
        • 1970-01-01
        • 1970-01-01
        • 2020-07-13
        • 1970-01-01
        • 2023-02-04
        • 1970-01-01
        • 1970-01-01
        • 2017-07-12
        相关资源
        最近更新 更多