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

Popular posts from this blog

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -