PTA counts the number of sales for each item. score 3

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:

Sample output:

Sample output:

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

Guess you like

Origin blog.csdn.net/weixin_70206677/article/details/129345043