我一直在case语句中添加min函数并收到错误。这是不允许的还是我只是做错了什么?
之前我用这个最小日期构建了一个虚拟表并链接到它,但这感觉效率很低。非常感谢任何帮助:
Exception: HttpExceptionRequest Request {
...
port = 443
...}
TlsNotSupported
答案 0 :(得分:1)
这是您编写的查询。我突出显示了明显的语法错误
SELECT UNIQUE_ID,
sum(CASE WHEN TRAN_TYPE NOT IN ('D') THEN 0
WHEN TRANSACTION > 0 THEN TRAN_AMNT
WHEN (TRAN_DATE > (min(CASE WHEN TRAN_TYPE = 'N' THEN TRAN_DATE ELSE null END) + 30))
-----------------------------------^ aggregation function within an aggregation function
THEN 0
ELSE TRAN_AMNT
END) as GROSS_LOSS
FROM TABLE_NAME
WHERE TRAN_DATE BETWEEN '2003-01-01' AND '2018-02-28' AND -- fixed the date formats
TRAN_TYPE NOT IN ('X') AND
-----------------------------^ And what?
GROUP BY UNIQUE_ID,
------------------^ extra comma
HAVING sum(TRAN_AMNT) >= 5000000;
您的问题的答案是您无法嵌套这样的聚合函数。您还需要修复其他错误。
建议解决什么问题有点困难,因为你没有描述你真正想要的逻辑。