+ 4
Write a query to output the average of Sam's exam scores for the first semester.
Select avg(score) from sam_grades; How can add that the score i sonly for 1 semester?
7 ответов
+ 5
select AVG(score)
FROM sam_grades
where semester = '1';
+ 2
SELECT AVG (score)
FROM sam_grades
WHERE semester=1;
+ 1
Can you share sample data or more detail about the table structure?
If sam_grades table had a semester_id field, you could do something like this:
Select semester_id, avg(score) from sam_grades group by semester_id;
This would be a separate average for each and every semester.
If you just want to average only semester 1 and you had a semester_id field, you could filter down to that like this:
Select avg(score) from sam_grades where semester_id=1;
Since the table name is "sam_grades", it sounds like there are no other student's grades in that table. This means there would be no need to filter with something like username='Sam';
+ 1
Thanks :)
0
Thats really simple
SELECT avg(score) from sam_grades
where semester in(1);
using sub query we can do
0
SELECT AVG(score) FROM sam_grades
WHERE semester=1;
0
SELECT AVG(score)
FROM sam_grades
WHERE semester = 1;