I need to find all members in the database with data on 7 or more consecutive days. The table is set up as member_id and data_date. There are duplicate member_ids for each day that there is data.
I found some answers using MySQL that involved datediff
or dateadd
, but I am not sure how to do this in PostgreSQL 8.2.15. Below is an example of what the table looks like, but with many more rows.
+------------+------------+
| member_id | data_date |
+------------+------------+
| 0000001 | 2018-04-10 |
| 0000005 | 2018-04-16 |
| 0000001 | 2018-04-11 |
| 0000002 | 2018-04-12 |
| 0000003 | 2018-04-13 |
| 0000004 | 2018-04-12 |
| 0000005 | 2018-04-15 |
| 0000003 | 2018-04-19 |
| 0000002 | 2018-04-17 |
| 0000001 | 2018-04-18 |
| 0000005 | 2018-04-10 |
| 0000002 | 2018-04-18 |
| 0000001 | 2018-04-08 |
| 0000002 | 2018-04-03 |
| 0000003 | 2018-04-02 |
| 0000004 | 2018-04-14 |
| 0000005 | 2018-04-15 |
| 0000003 | 2018-04-16 |
| 0000002 | 2018-04-19 |
| 0000001 | 2018-04-14 |
+------------+------------+
(member_id, data_date)
is defined UNIQUE
.