- Joined
- Mar 4, 2002
- Location
- Winnipeg, Manitoba, Canada
I have a table of users that has records entered in it every hour with their updated "credit" which either increase or stays the same.
I want to write a select statment that returns the data in the row that contains the largest value for credit for each individual user on a particular day.
It will also sort by credit but that parts easy.
Here's what I have
SELECT userid, name, MAX(currentcredit) as current_credit, rac, country FROM userstats
WHERE month='6' AND day='4' AND year='2008'
GROUP BY userid
ORDER BY current_credit DESC
This give me the maximum credit for each user but the other columns(rac is what I really need to be from the matching row) it returns aren't from the row that contains the maximum credit amount, they're from the first row that userid is found in.
I want to write a select statment that returns the data in the row that contains the largest value for credit for each individual user on a particular day.
It will also sort by credit but that parts easy.
Here's what I have
SELECT userid, name, MAX(currentcredit) as current_credit, rac, country FROM userstats
WHERE month='6' AND day='4' AND year='2008'
GROUP BY userid
ORDER BY current_credit DESC
This give me the maximum credit for each user but the other columns(rac is what I really need to be from the matching row) it returns aren't from the row that contains the maximum credit amount, they're from the first row that userid is found in.
Last edited: