Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As I said on the comments: you should have a table with all days and left join with your interval and use a SUM instead COUNT. The count only bring results for those that exists in your table. Say that your interval is from <code>2013-01-01 to 2013-01-10</code> and you have theese registries: </p> <pre><code>Created 2013-01-01, 2013-01-01, 2013-01-02, 2013-01-03 </code></pre> <p>it will result in: <code>2, 1, 1</code></p> <p>there is no way for the sql to know that should exist <code>01-04, 01-05, 01-06... 01-10</code></p> <p>So you have to create the data of the days and left join with your table. Something like this: </p> <p>Some data example:</p> <pre><code>create table tbl_users( created date ); insert into tbl_users values ( '2013-11-24' ), ( '2013-11-24' ), ( '2013-11-25' ), ( '2013-11-25' ), ( '2013-11-25' ), ( '2013-11-26' ), ( '2013-11-27' ), ( '2013-11-27' ), ( '2013-11-27' ), ( '2013-11-28' ), ( '2013-11-29' ); create table alldays ( dateday date ); --this is just an example to fit the result for today: 2013-11-28 --this table should have all days for the year insert into alldays values ( '2013-11-23' ), ( '2013-11-24' ), ( '2013-11-25' ), ( '2013-11-26' ), ( '2013-11-27' ), ( '2013-11-28' ), ( '2013-11-29' ), ( '2013-11-30' ), ( '2013-12-01' ), ( '2013-12-02' ), ( '2013-12-03' ); </code></pre> <p>Your query should be:</p> <pre><code> SELECT a.dateday, sum( if(b.created is null, 0, 1) ) FROM alldays a left join tbl_users b on (a.dateday=b.created) WHERE a.dateday &gt;= date_sub(curdate(), INTERVAL 7 DAY) AND a.dateday &lt;= NOW() GROUP BY a.dateday </code></pre> <p>See it here: <a href="http://sqlfiddle.com/#!2/cee122/7" rel="nofollow">http://sqlfiddle.com/#!2/cee122/7</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload