SQL Teradata评估顺序的情况下,否则

时间:2015-06-18 09:59:48

标签: sql teradata operator-precedence case-when

我想在官方Teradata Express for VMware Player(使用Viewpoint的TDE 15.00.01 SLES 10 for VMware(40GB))上运行此查询:

SELECT 'MaxValue' column_name,
       COUNT("MaxValue") AS count_value,
       COUNT(DISTINCT("MaxValue")) AS count_dist_value,
       MIN("MaxValue") AS min_value,
       MAX("MaxValue") AS max_value,
       CASE WHEN max_value > 99999999999999 THEN 99999999999999
            ELSE SUM("MaxValue") END AS sum_value
FROM (SELECT TOP 100 * FROM "DBC"."IdCol") AS xy;

但是我收到了这个错误:

  

作为单一陈述执行。失败[2616:22003]数字溢出   在计算过程中发生经过时间= 00:00:00.115

     

声明1:选择声明失败。

所以我的问题是,为什么在CASE逻辑为True时评估ELSE语句?我该如何运行此查询?我想要来自未知表的COUNT,MIN,MAX,AVG,SUM等信息,我不知道列是否包含20位长数。 谢谢!

1 个答案:

答案 0 :(得分:0)

根据DrCopyPaste的评论,解决方案是:

SELECT 'MaxValue' column_name,
       COUNT("MaxValue") AS count_value,
       COUNT(DISTINCT("MaxValue")) AS count_dist_value,
       MIN("MaxValue") AS min_value,
       MAX("MaxValue") AS max_value,
       CASE WHEN max_value > 99999999999999 THEN 99999999999999
            ELSE SUM(CAST("MaxValue" AS BIGINT)) END AS sum_value
FROM (SELECT TOP 100 * FROM "DBC"."IdCol") AS xy;

谢谢!