Question stem:
Count the number of sales for each item.
Tip: Please use the SELECT statement to answer.
Table Structure:
The SQL statement defining the table structure is as follows:
CREATE TABLE recorder(
id INT PRIMARY KEY AUTO_INCREMENT,
cid CHAR(4),
gid CHAR(4),
quantity INT NOT NULL,
sale_date DATETIME,
CONSTRAINT salrecorder_cid_fk FOREIGN KEY (cid) REFERENCES customer(cid),
CONSTRAINT salrecorder_gid_fk FOREIGN KEY (gid) REFERENCES good(gid)
);
table sample
Table example corresponding to the above table structure:
recorder table:
![](https://img-blog.csdnimg.cn/img_convert/3470f2fbbe3ad6f103d4fff943db2b0d.png)
Sample output:
Sample output:
![](https://img-blog.csdnimg.cn/img_convert/50d43fec0d8e56366fae6db2e81a74fd.png)
Code length limit 16 KB
Time limit 400 ms
DatabaseMySQL
The result output requires a strict comparison of the order and data
select gid 商品编号, sum(quantity) 销售总数量
from recorder
group by gid
![](https://img-blog.csdnimg.cn/img_convert/d6360cc7a990af167636034167ff323a.png)