1

I want to fetch the data from Table based on date but in an incremental way.

Suppose I have data like this which is grouped by date

| DATE       | Count |
| 2015-06-23 | 10    |
| 2015-06-24 | 8     |
| 2015-06-25 | 6     |
| 2015-06-26 | 3     |
| 2015-06-27 | 2     |
| 2015-06-29 | 2     |
| 2015-06-30 | 3     |
| 2015-07-01 | 1     |
| 2015-07-02 | 3     |
| 2015-07-03 | 4     |

So the result should come like this

| DATE       | Count| Sum|
| 2015-06-23 | 10   | 10 |
| 2015-06-24 | 8    | 18 |
| 2015-06-25 | 6    | 24 |
| 2015-06-26 | 3    | 27 |
| 2015-06-27 | 2    | 29 |
| 2015-06-29 | 2    | 31 |
| 2015-06-30 | 3    | 34 |
| 2015-07-01 | 1    | 35 |
| 2015-07-02 | 3    | 38 |
| 2015-07-03 | 4    | 42 |
Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
Gathole
  • 892
  • 1
  • 13
  • 24

1 Answers1

0

You would join every other previous date on that date, and then sum the count on that If you give me your table structure, I can make it run. id, name, date_joined

SELECT counts.theCount, sum(counts.theCount), table.date_joined
FROM yourTable
LEFT JOIN 
(SELECT count(*) as theCount, table.date_joined
 FROM yourTable
 GROUP BY table.date_joined
) as counts
ON
yourTable.date_joined> counts.date_joined
GROUP BY yourTable.date_joined
Paul Stanley
  • 4,018
  • 6
  • 35
  • 56