我必须做以下事情:
按照上周的最高到最低的顺序,为 persona = 'z' 的用户排名。
我写了以下代码:
SELECT U.*, SUM(T.amount) AS total_spends FROM User U JOIN Transact T ON U.id = T.created_by WHERE U.persona = 'Z' AND T.date_created >= CURRENT_DATE - INTERVAL '1 week' GROUP BY U.id ORDER BY total_spends DESC;
但是,我得到了以下错误: 错误:附近的 "'1 week'":语法错误
任何帮助将不胜感激。
P粉5140018872023-09-15 14:28:09
SELECT U.*, SUM(T.amount) AS 总支出 来自用户 U JOIN 交易 T ON U.id = T.created_by WHERE U.persona = 'Z' AND T.date_created >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) 按 U.id 分组 ORDER BY 总支出 DESC;