Querying database for TLH per account

Read 2507 times
Hi,

I'm looking to develop a simple SQL script that will tell me the total TLH per stream, something like this:

SELECT accountid, SUM( duration ) / 3600
FROM  `visitorstats_sessions`
WHERE endtime >=  '2016-08-08'
AND endtime <  '2016-08-15'
GROUP BY accountid
ORDER BY accountid

The results I'm getting is different (not by much) to the figures in the actual Centova user panel. I've tried changing the endtime to starttime etc, and still it's different.

I'm believing that my figures are incorrect as the sessions could span two days, i.e. if the user started listening before midnight the day before, or the user started listening before midnight on the same day but stopped the session after the current day.

Can someone help me reconcile the two figures?

Thanks