我想寫一個SQL查詢輸出產品的識別號碼(p_id),以及去年(2016年)銷售的數量和生成的美元金額。如何處理錯誤1064?
下面是我的代碼
mysql> select id,
-> sum(quantity) as Quantity_Sold
-> sum(amt_paid) as Purchase
-> from transaction
-> where order_date like '%2016%'
-> group by p_id;
以下是表我試圖查詢形式
select * from transaction;
+------+------+------+------------+---------------+----------+------+----------+
| T_ID | P_ID | ID | ORDER_DATE | DELIVERY_DATE | QUANTITY | SP | AMT_PAID |
+------+------+------+------------+---------------+----------+------+----------+
| T1 | P1 | C2 | 2001-01-16 | 2001-02-01 | 2 | 100 | 200 |
| T10 | P11 | C11 | 2001-06-13 | 2001-06-20 | 3 | 25 | 75 |
| T100 | P11 | C11 | 2004-12-06 | 2004-12-11 | 6 | 25 | 150 |
| T101 | P6 | C3 | 2005-01-07 | 2005-01-12 | 1 | 35 | 35 |
| T102 | P3 | C4 | 2005-01-11 | 2005-01-16 | 4 | 120 | 480 |
| T103 | P12 | C5 | 2005-01-26 | 2005-01-31 | 3 | 90 | 270 |
它提供了以下錯誤 錯誤1064(42000):你有一個錯誤的SQL語法;檢查對應於你的MySQL服務器版本在線路附近使用「總和(數量)的數量 總和(amt_paid)作爲購買 其中order_date的LIKE‘%2016’正確的語法手冊2
enter code here
看起來像是在quanity_sold之後缺少一個逗號。 –