我想写一个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之后缺少一个逗号。 –