代码之家  ›  专栏  ›  技术社区  ›  user6866797

配置单元Case语句参数类型与不匹配

  •  0
  • user6866797  · 技术社区  · 6 年前

    在配置单元中运行以下代码时出现以下错误:

    04:08:12[SELECT-0行,0.096秒][代码:40000,SQL状态:42000]编译语句时出错:失败:SemanticException行0:-1参数类型不匹配“2018-02-14”:WHEN之后的表达式应具有与after CASE相同的类型:应为“date”,但找到“boolean”

    Select
                case shipped_date
                        when shipped_date between cast ('2018-02-01' as date) and cast ('2018-02-14' as date) then 1
                        when shipped_date between cast ('2018-02-18' as date) and cast( '2018-03-03'as date) then 2
                        when shipped_date between cast ('2017-02-01' as date) and cast ('2017-02-14'as date) then 3
                        when shipped_date between cast ('2017-03-12' as date) and cast ('2017-03-25' as date) then 4
                        when shipped_date between cast('2018-04-30' as date) and cast ('2018-05-13'as date) then 5
                        when shipped_date between cast ('2018-03-27' as date) and cast('2018-04-09'as date) then 6
                        when shipped_date between cast('2017-04-28'as date) and cast ('2017-05-14'as date) then 7
                        when shipped_date between cast ('2017-03-26' as date) and cast ('2017-04-11' as date) then 
    
                end as test_period,department_name
                from my_table;
    

    有人知道如何解决这个错误吗?

    谢谢!

    1 回复  |  直到 6 年前
        1
  •  1
  •   Samson Scharfrichter    6 年前

    选择一种情况下的语法,不要混用两者!

    case EXPRESSION when EXPR_VALUE then OUT_VALUE

    case when CONDITION then OUT_VALUE

    所以,在你的案例后面去掉“发货日期”。