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.
Author |
Topic |
Avalon
Starting Member
2 Posts |
Posted - 2007-12-04 : 12:59:52
|
I have the following tables: What I want to find out is the average LevelID for each QuestionID. The query I have so far is:SELECT Questions.QuestionID, Questions.Quesion, Levels.LevelID, Levels.LevelName, Avg(Levels.LevelID) AS AvgOfLevelIDFROM Questions INNER JOIN (Survey INNER JOIN (Levels INNER JOIN Rating ON Levels.LevelID = Rating.LevelID) ON Survey.SurveyID = Rating.SurveyID) ON Questions.QuestionID = Rating.QuestionIDGROUP BY Questions.QuestionID, Questions.Quesion, Levels.LevelID, Levels.LevelName;(generated from Access) but it's not working correctly. Can someone help?If there are say, 8 questions, I want the query to only return 8 numbers. |
|
tacket
Starting Member
47 Posts |
Posted - 2007-12-04 : 17:28:27
|
What's the data look like in Levels? When you say average, that basically means you take the total of all the levels (which I have no idea what column that is in the levels table) divided by the the total number of questions, so there had better be another column in levels which is an integer indicating the level. Let's assume there is then you would just do something like this:select surveyID,questionID,question,sum(level) / count(*)from rating ainner join questions bon b.questionID = a.questionIDinner join levels con c.levelID = a.levelIDinner join suver don d.surveyID = a.surveyIDgroup by surveyID,questionID,question |
 |
|
Avalon
Starting Member
2 Posts |
Posted - 2007-12-05 : 08:21:24
|
The integer column that indicates the rating level is levelID. |
 |
|
tacket
Starting Member
47 Posts |
Posted - 2007-12-05 : 14:57:14
|
What's the data look like in Levels? When you say average, that basically means you take the total of all the levels (which I have no idea what column that is in the levels table) divided by the the total number of questions, so there had better be another column in levels which is an integer indicating the level. Let's assume there is then you would just do something like this:select surveyID,questionID,question,sum(level) / count(*)from rating ainner join questions bon b.questionID = a.questionIDinner join levels con c.levelID = a.levelIDinner join suver don d.surveyID = a.surveyIDgroup by surveyID,questionID,question |
 |
|
tacket
Starting Member
47 Posts |
Posted - 2007-12-05 : 15:02:05
|
Sorry about the duplicate post there. Yea, then just replace sum(level) w/ sum(levelID) and then you should be good to go. |
 |
|
|
|
|
|
|