4 回答
TA贡献1785条经验 获得超8个赞
正确的方法如下:
DROP TABLE IF EXISTS my_table;
CREATE TABLE my_table
(id SERIAL PRIMARY KEY
,srno INT NOT NULL
,subject VARCHAR(20) NOT NULL
,mark INT NOT NULL
);
INSERT INTO my_table VALUES
(1,1,'english',52),
(2,1,'maths',52),
(3,1,'science',52);
SELECT srno
, SUM(mark) total
FROM my_table
GROUP
BY srno;
+------+-------+
| srno | total |
+------+-------+
| 1 | 156 |
+------+-------+
TA贡献1842条经验 获得超12个赞
尝试这样的事情:
SELECT srno, name, english, maths, science, (english+maths+science) As TotalMarks FROM `table_name`
TA贡献1827条经验 获得超8个赞
那么你可以试试这两种方法:
select * from Your_Table_Name;
当您显示结果时,您可以添加所有这些值,例如:
srno name english maths science TotalMarks
$id $name $english $maths $science ($english+$maths+$science)
或者
select id, name, english, math, science, (english+maths+science) as Total from Your_Table_Name;
- 4 回答
- 0 关注
- 114 浏览
添加回答
举报