我有一个表格,其中包含特定日期的名称(varchar),日期(日期时间)和收入(金钱)
实施例
robert 10/10/13 1200.0000
jacob 10/10/19 2300.0000
如何计算特定日期的总收入(例如从10/10/13到10/10/28)
答案 0 :(得分:2)
为了所有人:
SELECT name_column, sum(IFNULL(amount_column, 0))
FROM income_table
WHERE date_column BETWEEN '[INSERT FROM DATE]' AND '[INSERT UNTIL DATE]'
GROUP BY name_columns
一个人:
SELECT sum(IFNULL(amount_column, 0))
FROM income_table
WHERE date_column BETWEEN '[INSERT FROM DATE]' AND '[INSERT UNTIL DATE]'
AND name_column = '[INSERT NAME]'