I have a table with the following structure:
id | service_name | subscribers_count | date
1 | service 1 | 1 | 2017-07-01 01:01:01
2 | Service 1 | 2 | 2017-07-01 01:01:02
3 | Service 1 | 3 | 2017-07-02 01:01:01
4 | Service 1 | 2 | 2017-07-03 01:01:01
5 | Service 1 | 3 | 2017-07-04 01:01:01
6 | Service 2 | 1 | 2017-07-01 01:01:01
7 | Service 2 | 2 | 2017-07-01 01:01:02
8 | Service 2 | 3 | 2017-07-01 01:01:03
9 | Service 2 | 4 | 2017-07-02 01:01:01
It's easy to fetch the last record for each service, but I need more - I need to fetch the last record for each service for each day. This is what I expect to get:
2 | Service 1 | 2 | 2017-07-01 01:01:02
3 | Service 1 | 3 | 2017-07-02 01:01:01
4 | Service 1 | 2 | 2017-07-03 01:01:01
5 | Service 1 | 3 | 2017-07-04 01:01:01
8 | Service 2 | 3 | 2017-07-01 01:01:03
9 | Service 2 | 4 | 2017-07-02 01:01:01
What's the most effective way to write it?