Reputation: 5016
How can I run the following query in PostgreSQL (the following should work on MSSQL). The purpose is to see how much time apart to evens happened:
select ABS(CAST((a.timefield - b.timefield) as INT)) as 'Time Apart'
from a inner join b on (a.id = b.id);
Upvotes: 0
Views: 77
Reputation: 62613
Depending on the type of "a.timefield" and "b.timefield" this should work:
SELECT ABS(EXTRACT(EPOCH FROM (a.timefield - b.timefield))) AS "Time Apart" FROM a INNER JOIN b ON (a.id = b.id);
Upvotes: 1
Reputation:
SELECT a.timefield - b.timefield FROM a INNER JOIN B on (a.id = b.id)
Will give you an interval data type
Upvotes: 0