I have a table of news articles, articles
, each of which have a date
attribute. Most days have multiple articles recorded, some days have none at all.
I'd like to be able to get a selection of articles with varying granularity - for instance, one per day, one per month, etc. I've found questions that deal with daily and even monthly, but as a user can select granularity (for instance, one article per 3 days), having multiple queries to deal with each possible level of granularity isn't feasible
Is this something possible using SQL, or will every article need to be selected, and then filtered through using a different language?
Maybe granularity is the wrong word - here's an example of the table:
id | date | headline |
---|---|---|
1 | 2020-01-01 | This one weird trick... |
2 | 2020-01-01 | These two weird tricks... |
3 | 2020-01-01 | These fifty weird tricks... |
4 | 2020-01-02 | This one crazy trick... |
5 | 2020-01-02 | This one odd trick... |
6 | 2020-01-03 | These tricks... |
7 | 2020-01-04 | These tricks... |
8 | 2020-01-05 | These tricks... |
With a granularity of one day, the query should return rows 1, 4, 6, 7, 8. With a granularity of 3 days, 1 and 7 will be picked, as 7 is the first record that's 3 days after the first.