user10788762
user10788762

Reputation: 3

SQL AVG() confusion basic SQL

Part of my assignment says this 6. Display the student id and average score for each student.

This is what I came up with

SELECT student_id, AVG(score) FROM scores;

But it only brings up the average score of the first student. What do I need to change?

Upvotes: 0

Views: 39

Answers (2)

Revathi Ganesh
Revathi Ganesh

Reputation: 119

Please try this query with GROUP BY

SELECT student_id, AVG(score) FROM scores GROUP BY student_id

Upvotes: 0

jcyan
jcyan

Reputation: 61

You need a groupby operator.

SELECT student_id, AVG(score) FROM (table_name) GROUPBY student_id

Maybe, the table like this,

|class_id|class_name|student_id|student_name|score|

You have to decribe your table in detail. Anyway, I think GROUPBY is all you need in this question.

Upvotes: 1

Related Questions