Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Average query with 2 rows from same table
March 7, 2006, 5:16 pm
rate this thread
My first post in this group, so hope some of you can help me.
answer1 is questionID = 1
answer2 is questionID = 2
WHERE userID is the same for both answer1 and answer2
I want the average of answer1/answer2: AVG(ans1/ans2), but how?
Hope you will help me
Re: Average query with 2 rows from same table
If you need to compare two rows from the same table, you need to do a
Try something like this:
SELECT a1.userID, AVG(a1.answer/a2.answer)
FROM answer AS a1
INNER JOIN answer AS a2 ON a1.userID = a2.userID
AND a1.questionID = 1 AND a2.questionID = 2
GROUP BY a1.userID
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum