SQLite:搜索并求和相似的值

时间:2016-04-07 15:52:12

标签: database sqlite sum

我有这张桌子:

pupil_id | mark | month | year

数据:

01 | 4 | February | 2015
02 | 6 | September| 2014
01 | 3 | February | 2015 
02 | 5 | September| 2014

pupil_id | month | year | sum(mark)的预期结果是:

01 | February | 2015 | 7
02 | September | 2014 | 11

我如何总结相似的值?

1 个答案:

答案 0 :(得分:2)

使用GROUP BY可以为您提供所需的结果。

SELECT pupil_id, month, year, SUM(mark)
FROM marks
GROUP BY pupil_id, month, year