I have a table:
ID int
category int
quantity int
timestamp timestamp
I want to SELECT id=”id#” and return a ‘position’ which is the sum of quantity for each row that has an earlier timestamp in the same category.
Thanks for your pointers!
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.
Try this:
If you want to select by id:
UPDATE
To use the timestamp from the row itself, you could do something like:
..or use a self-join as in the Adam’s answer (maybe it wasn’t an overkill, after all.. :))
UPDATE – Alternate solution
This seems to work fine too..
UPDATE
Changed
<into<=, else the quantity for the selected item will not be counted!