【发布时间】:2015-04-23 00:44:58
【问题描述】:
我有两个 SQL 表。
在第一个表中,每一行都有(在与问题无关的其他字段中)score 和 category_id 字段
第二个表 (categories) 是一个表,其中列出了第一个表中的元素可以属于的所有可能类别。
我想做以下 SQL 请求:
SELECT category_name, ( ??? ) AS category_score
FROM categories
ORDER BY category_score DESC
??? = the sum of the scores of all the elements in table 1 that belong to the category.
【问题讨论】: