我想通過將購物車中每個產品的值相加來計算一個用戶購物車中的總產品。如何獲得數據庫中多列的Mysql SUM
我使用這個查詢:
SELECT *, SUM(quantity) OVER (PARTITION BY product_id ORDER BY id) AS TotalProducts
FROM cart WHERE user_id ='$user_id';
四處錯誤:
SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(PARTITION BY product_id ORDER BY id)
編輯與DB模式
id | product_id | quantity | user_id
1 | 37 | 2 | 23847
2 | 70 | 2 | 23847
我看不到我做錯了什麼?
'AS TotalProducts,'<<<刪除逗號一兩件事,這是一個錯字。 –
@ Fred-ii-:逗號被刪除,仍然 –