SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help performing a query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nitzanma
Starting Member

4 Posts

Posted - 12/31/2012 :  06:31:52  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/31/2012 :  09:23:43  Show Profile  Reply with Quote
So what have you tried?
Go to Top of Page

nitzanma
Starting Member

4 Posts

Posted - 12/31/2012 :  13:18:09  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 12/31/2012 :  13:34:49  Show Profile  Reply with Quote
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 - 01/01/2013 :  03:45:57  Show Profile  Reply with Quote
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

Pakistan
885 Posts

Posted - 01/01/2013 :  10:01:40  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
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 - 01/02/2013 :  03:28:02  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000