I have MySQL table with structure like
lesson_id | task_id | user_id | mark
There can be many users and tasks on each lesson
I want to get 2 results :
Expected result 1.
user_1 500
user_3 423
user_2 100
user_4 92
Expected result 2.
user_id | mark | lesson_id
user_3 | 423 | 2
user_2 | 100 | 2
user_4 | 92 | 2
I agree with scaisEdge about the 1st question for the 2nd question you need to add filtering by lesson to the same query:
select user_id, sum(mark) sum_of_mark
from your_table
group by user_id
where lesson_id = @lesson
order by sum_of_mark DESC;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments