1

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;

1 Answer 1

1

Assuming that sentdate is a date/timestamp field then this ought to work:

SELECT COUNT(*),
    date_part('hour', sentdate ) AS hour
FROM latency l,
    contacts me
WHERE l.lat < 1
    AND date_trunc ('day', sentdate) > DATE ( '2009-01-01' )
    AND date_trunc ('day', sentdate) < DATE ( '2011-02-01' )
    AND ( me.id = l.replyuid
        OR me.id = l.senduid )
GROUP BY date_part('hour', sentdate )
ORDER BY hour ASC;
Sign up to request clarification or add additional context in comments.

2 Comments

If I were writing this query, I might try to make this an inner join (instead of comma join), and since there's an or in the join conditiion, I'd express that as a union, same query, but maybe more idiomatic sql.
@TokenMacGuy - true enough. I very much prefer ANSI joins, however I was trying not to deviate too far from the original query...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.