0

I have the following query:

SELECT count,date FROM clicks WHERE page_id = ? AND date >= DATE(NOW()) - INTERVAL 7 DAY

This works, but it only fetches the days where I have clicks (counted).

For example (records in database):

Date          Count
01/01/2018    1
03/01/2018    3
04/01/2018    2
05/01/2018    3
07/01/2018    3

In this example, 02/01/2018 and 06/01/2018 are not fetched because they don't exist in the database.

My question is now: can I 'add' these dates with SQL and add a count '0' to them?

Sam Leurs
  • 480
  • 4
  • 20
  • If that is your returned array then just loop it and add to database if the datediff or Unix seconds are more than 86400 apart between items. – Andreas Jun 18 '18 at 20:28
  • I was writing you an answer when you got marked duplicate - and I don't like the existing answers on that question either. Please see my new answer there that was initially written for you and modified to fit that question. I can PM you the version written for you if you'd like. https://stackoverflow.com/a/50918062/8327405 – Michael Conard Jun 18 '18 at 22:03

0 Answers0