var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: timediff mysql query to postgres
I have the next query in mysql to get the time difference from two rows, but I would like to implement it in postgres, but I'm getting some errors when I try to query it.
timediff(@nexttime,date) as tdiff2, (@nexttime:=date) as Next
where speed=0 and mobile = 1883 and date >(now() - interval 2 hour)
I have changed the last part to: (now() - interval '2 hours') but I go on getting another error in the Timediff command.
Can anyone help me please?
And the errors are?
Is not valid Postgres syntax. What is that supposed to do?
(@nexttime:=date) as Next
What's that @nexttime supposed to do?
And please use [code] text to format your SQL statements and make them better readable.
What I want to do is something like this:
Date Timediff (result)
14-12-2010 20:25:40 00:01:05
14-12-2010 20:26:45 00:00:15
14:12-2010 20:27:00 ......
So, the result would be: the substract of the dates to get how much time have spent from the last date
The errors is that the function timediff doesnt exist in postgres.
Originally Posted by franrtorres77
SELECT date1 - date2
but, how do I substract the bellow row with the upper row?
For future posts please remember:
SELECT the_column_with_no_name - lag(the_column_with_no_name) over (order by the_column_with_no_name asc)
1) post the full definition of your table as a CREATE TABLE statement
2) post sample data as INSERT INTO statements
3) post the expected result from the sample data
this helps us finding a proper solution for your problem
It works! thank you very much! I will have in mind your recommendatios for the next posts.
Thank you again!