I’m trying to improve a routine in my program where I’m counting the number of occurrences of the same date.
So maybe an example:
Time Other_stuff Entry
1332334357 .....
1332334367 .....
1332334386 .....
Till now I’ve used a statement like :
SELECT date(time, 'unixepoch') FROM reviewHistory
WHERE lastInterval <= 21 AND nextInterval > 21
Now I basically want to generate a histogram of the entries falling on the same date
2012-03-21 20
2012-03-20 13
2012-03-19 50
And so on. However I don’t see an easy way to do this so I figured I would simply do a SELECT DISTINCT and store those values and then query for each distinct entry with the conditionals and check the row count. It’d save me processing time and I/O access time however I haven’t been able to find a statement that accomplishes this. I thought something like this would work but it doesn’t. Example:
SELECT time FROM reviewHistory WHERE
(SELECT date(time, 'unixepoch') FROM reviewHistory
WHERE lastInterval <= 21 AND nextInterval > 21) = "2012-03-21"
It doesn’t error but it also doesn’t return anything and I feel pretty sure that this is something that I should be able to accomplish in a few SQLite statements and not have to manage application side.
UPDATE: Lol it just came to me after I posted it. Though I still want to believe there’s a more graceful way to accomplish the tallying problem in SQL.
SELECT time FROM
(SELECT date(time, 'unixepoch') AS time
FROM reviewHistory WHERE lastInterval <= 21 AND nextInterval > 21)
WHERE time = "2012-03-21"
I’m not sure if I understand your question, but to get all dates and the counts, one query should be sufficient: