mysql - SQL: how to select something using information from another table -


i have 2 sql tables.

in first table, each line has (amongst other fields irrelevant question) score , category_id field

the second table (categories) table listing possible categories element in first table can belong.

i'd following sql request :

select category_name, ( ??? ) category_score categories order category_score desc 

where ??? = the sum of scores of elements in table 1 belong category.

you join , group by:

select   category_name, sum(score) category_score     categories c join     element e on c.category_id = e.category_id group category_name  order 2 desc 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -