Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help performing a query

Author  Topic 

nitzanma
Starting Member

4 Posts

Posted - 2012-12-31 : 06:31:52
i have 4 columns:
User ID
Subject (of a question)
Question ID
Question Grade

i.e. i got users that solve questions in several subjucts - and all their achievements are documented in the db.

I would like to present user's average grade in each subject

meaning that the output will be:
UserID Subject AverageGrade

how can i do that?

thank you very much!

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-31 : 09:23:43
So what have you tried?
Go to Top of Page

nitzanma
Starting Member

4 Posts

Posted - 2012-12-31 : 13:18:09
quote:
Originally posted by sodeep

So what have you tried?



i have very basic knowledge, i know to perform quite simple queries, and here i know it probably needs nested queries, but i just don't have an idea how to begin.

if it wasn't clear -
each questionGrade belongs to QuestionID.
and each QuestionID belongs to a Subject (represented by int)
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-12-31 : 13:34:49
Your question was clear, it just looks like a homework question, and most people here are reluctant to do other people's homework for them. However, if you give it your best shot first, people here are very willing to help you along.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

nitzanma
Starting Member

4 Posts

Posted - 2013-01-01 : 03:45:57
this is no homework.
it might sound like that, because i tried writing it the simplest way i could.
I'm doing a research, that includes some data mining, but mostly in a basic way.
I'm willing to make this query work, so I can take it to Weka, and find some interesting association rules.

your help will be very appreciated.
best regards.
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2013-01-01 : 10:01:40
SELECT [User ID],[Subject],AVG([Question Grade]) AS Avg_Grade
FROM yourResultTable
GROP BY [User ID],[Subject]


--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

nitzanma
Starting Member

4 Posts

Posted - 2013-01-02 : 03:28:02
quote:
Originally posted by lionofdezert

SELECT [User ID],[Subject],AVG([Question Grade]) AS Avg_Grade
FROM yourResultTable
GROP BY [User ID],[Subject]


--------------------------
http://connectsql.blogspot.com/



thanks a lot!
i couldn't figure this is so simple!
i was positive that it will do average to all records.
now i understand the use in group by

thanks again (:
Go to Top of Page
   

- Advertisement -