Teradata - 案例陈述中的嵌套聚合操作
Teradata - Nest Aggregate Operations in Case Statement
我在尝试下面的 运行 脚本时遇到错误 "cannot nest aggregate operations"。我搜索了具有类似标题的其他问题,但他们没有解决这个问题。
我正在尝试对一个时期的数据求和,对同一时期的其他数据求和,然后从另一个中减去一个。在我看来很简单!有人可以帮忙吗?
SELECT
SUM(CASE WHEN a.post_ts(DATE) between 1140921 and 1140927 THEN (pnt_amt(DEC (16,0)))
- sum ((dlr_val*1000)*-1)END) Week 34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
或者这个:
Sel
SUM(CASE WHEN a.post_ts(DATE) between 1140921 and 1140927 THEN (pnt_amt(DEC (16,0)))
- SUM(CASE WHEN a.post_ts(DATE) between 1140921 and 1140927 THEN sum ((dlr_val*1000)*-1)END)week_34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
我不知道你到底想做什么,但它可能是这样的:
SELECT
SUM(CASE WHEN a.post_ts(DATE) BETWEEN 1140921 AND 1140927 THEN (pnt_amt(DEC (16,0))) END
- SUM((dlr_val*1000)*-1)) Week 34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
或
SEL
SUM(CASE WHEN a.post_ts(DATE) BETWEEN 1140921 AND 1140927 THEN (pnt_amt(DEC (16,0))) END)
- SUM(CASE WHEN a.post_ts(DATE) BETWEEN 1140202 AND 1140208 THEN (dlr_val*1000)*-1 END)week_34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
顺便说一句,你可以简单地使用 -dlr_val*1000)
而不是 dlr_val*1000)*-1
并且你最好切换到 DATE '2014-02-02'
而不是 1140202
,这样更容易理解。
我在尝试下面的 运行 脚本时遇到错误 "cannot nest aggregate operations"。我搜索了具有类似标题的其他问题,但他们没有解决这个问题。
我正在尝试对一个时期的数据求和,对同一时期的其他数据求和,然后从另一个中减去一个。在我看来很简单!有人可以帮忙吗?
SELECT
SUM(CASE WHEN a.post_ts(DATE) between 1140921 and 1140927 THEN (pnt_amt(DEC (16,0)))
- sum ((dlr_val*1000)*-1)END) Week 34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
或者这个:
Sel
SUM(CASE WHEN a.post_ts(DATE) between 1140921 and 1140927 THEN (pnt_amt(DEC (16,0)))
- SUM(CASE WHEN a.post_ts(DATE) between 1140921 and 1140927 THEN sum ((dlr_val*1000)*-1)END)week_34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
我不知道你到底想做什么,但它可能是这样的:
SELECT
SUM(CASE WHEN a.post_ts(DATE) BETWEEN 1140921 AND 1140927 THEN (pnt_amt(DEC (16,0))) END
- SUM((dlr_val*1000)*-1)) Week 34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
或
SEL
SUM(CASE WHEN a.post_ts(DATE) BETWEEN 1140921 AND 1140927 THEN (pnt_amt(DEC (16,0))) END)
- SUM(CASE WHEN a.post_ts(DATE) BETWEEN 1140202 AND 1140208 THEN (dlr_val*1000)*-1 END)week_34
FROM DB.T1 b
,DB.T2 a
LEFT JOIN DB.T3 c ON A.OID = C.OID
WHERE a.lid = b.lid
顺便说一句,你可以简单地使用 -dlr_val*1000)
而不是 dlr_val*1000)*-1
并且你最好切换到 DATE '2014-02-02'
而不是 1140202
,这样更容易理解。