我必須做以下事情:
依照上週的最高到最低的順序,為 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'":語法錯誤
任何幫助將不勝感激。
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 >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY U.id ORDER BY total_spends DESC;