I have table with id, item_id, value (int), run (datetime) and i need select value diff betwen last two run per *item_id*.
I have table with id, item_id, value (int), run (datetime) and i need select
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe this should do the trick for you. Just replace
table_nameto correct name.Explanation:
Basicly I join the table with itself in a
run DESCorder, JOIN them based on item_id but also on id. Then I GROUP BY them again to remove potential 3rd and so on cases. Lastly I calculate the difference between them through ABS(value1 – value2).