I have another sqlite script that I need to convert to postgres. Take a gander if you can assist :)
SELECT count(*), strftime('%H', sentdate) as hour FROM latency l, contacts me
WHERE l.lat < 1 and datetime(sentdate) > datetime('2009-01-01') and datetime(sentdate)
< datetime('2011-02-01') and (me.id = l.replyuid or me.id = l.senduid)
GROUP BY hour ORDER BY hour asc;