mysql - Select users and order them by their article total views -
i have article table stores user id, article id , article views. want users table , order them total article views (sum).
see table below.
id | user_id | article_id | views 1 2 1 34 2 2 2 6 3 3 3 39 4 3 4 20
i want this.
user_id | views 3 59 2 40
i can views of 1 user using select sum(views) articles user_id = 2
, want users , order them total views.
add group by
clause , order by
clause:
select user_id, sum(views) sum_of_views articles group user_id order sum(views) desc
Comments
Post a Comment