我有一個樣本table這裏在SQL小提琴。如何獲得一列的總和
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
的Shots。並在秒的底部得到總數。
結果是錯誤的。任何人都可以指導我。
SELECT
IFNULL(Shot,'TOTAL') AS Shot
, sec
, lay
FROM my_table
where lay='1863'
group by shot with rollup;
結果在總(爲秒列)應爲7.75,現將其表示1
SHOT SEC LAY
SH01 3 1863
SH02 2.5 1863
SH04 1.25 1863
SH05 1 1863
TOTAL 7.75
你的意思是錯的?你想要什麼結果? – 2013-03-06 11:08:12
您的預期成果是什麼? – 2013-03-06 11:11:00