SQL分组求和

/*
DROP TABLE dbo.tqty;
CREATE TABLE dbo.tqty(
row_id INT PRIMARY KEY IDENTITY(1,1),
uid VARCHAR(90) NOT NULL,
class VARCHAR(90) NOT NULL,
score DECIMAL(11, 3));

INSERT INTO tqty(uid, class, score) VALUES
('001', '1', '2'),
('001', '2', '2'),
('001', '2', '2'),
('002', '2', '2'),
('003', '2', '2'),
('002', '2', '2');
*/

SELECT uid, class, sum(score) FROM dbo.tqty GROUP BY uid, class;

image

posted @ 2022-05-23 18:14  看不见的R  阅读(755)  评论(0编辑  收藏  举报