Sqlite Query Need To Tuned A Bit
Hi current i have code which will display the sum of records for last one hour in 10min interval. SELECT SUM(NO_OF_ADULT) AS ADULT , SUM(NO_OF_ADULT_F) AS ADULT_F , SUM(N
Solution 1:
- The database will not create records for data that isn't there.
If you want to get records for all time slots (and cannot handle this in your application when reading the result), you have to add records filled with zeros to the table. (You can do this blindly for all desired time slots, as the sums won't be affected.) - For strings in SQL, always use 'single quotes'. SQLite will accept double quotes for compatibility with some other SQL engines, but if you ever have some column with the same name, you will get hard-to-find errors.
- You do not need those
TIME(...)
calls; you can usestrftime('%H:%M','now','localtime')
directly. - To get ten-minute time slots based on the current time, you must do calculations without splitting the time into h/m/s fields. This was already shown in the previous question:
SELECT DATETIME(strftime('%s', SERVICE) +
((strftime('%s', 'now') - strftime('%s', SERVICE))
% (60 * 10)),
'unixepoch') ...
Post a Comment for "Sqlite Query Need To Tuned A Bit"