任何帮助表示赞赏。我试图在CASE语句中使用max(date),我无法正确获取语法或??
// This works
SELECT
ROUND(sum(CASE WHEN Document_Date BETWEEN DATE_FORMAT("2019-01-01", "%Y-%m-%d") AND DATE_FORMAT("2019-01-31", "%Y-%m-%d") THEN GTotal END),0) TOTAL2019
FROM
salesdata
// But I want to use max(Document_Date) which is 2019-01-31 like so and have tried cast and different combos, but it comes out null or says invalid use of group function. Document_Date is datetime in DB
SELECT
ROUND(sum(CASE WHEN Document_Date BETWEEN DATE_FORMAT("2019-01-01", "%Y-%m-%d") AND DATE_FORMAT(max(Document_Date), "%Y-%m-%d") THEN GTotal END),0) TOTAL2019
FROM
salesdata
我做错了什么 - 谢谢你的帮助。
你正试图在qazxsw poi中使用qazxsw poi aggregate。通常,如果不使用子查询,则无法执行此操作。
检查我的替代方案
max