我在 SQL Fiddle有一个示例表。
CREATE TABLE my_table
(id INT NOT NULL AUTO_INCREMENT UNIQUE,
Shot VARCHAR(4),
sec varchar(5),
lay VARCHAR(15) NOT NULL,
lay_status VARCHAR(15) NOT NULL,
blk VARCHAR(10) NOT NULL,
blk_status VARCHAR(15) NOT NULL,
pri VARCHAR(10) NOT NULL,
pri_status VARCHAR(15) NOT NULL,
ani VARCHAR(10) NOT NULL,
ani_status VARCHAR(15) NOT NULL,
status VARCHAR(5)
);
INSERT INTO my_table VALUES
(1,'SH01','3','1863','yes','1863','yes','P4645','yes','P4557','yes','Over'),
(2,'SH02','2.5','1863','yes','P4645','no','P4557','yes','1863','no','Over'),
(3,'SH03','0.5','P4645','yes','P4557','yes','1863','yes','1863','yes','WIP'),
(4,'SH04','1.25','1863','no','P4645','no','P4557','yes','1863','yes','RTK'),
(5,'SH05','1','1863','yes','1863','yes','P4645','yes','P4557','yes','WIP'),
(6,'SH06','6','P4557','yes','P4645','yes','P4645','yes','P4557','yes','WIP');
我使用下面的 SQL 来检索lay=1863
. 并在秒数的底部得到总数。
但结果是错误的。谁能指导我。
SELECT
IFNULL(Shot,'TOTAL') AS Shot
, sec
, lay
FROM my_table
where lay='1863'
group by shot with rollup;
总的结果(对于 sec 列)应该是 7.75,现在显示为 1
SHOT SEC LAY
SH01 3 1863
SH02 2.5 1863
SH04 1.25 1863
SH05 1 1863
TOTAL 7.75