Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含帖子的数据库,为了使其更简单,假设我有两个字段“用户”和“评分”。我想从用户的所有帖子中选择所有评级:“乔”并将它们加在一起并显示它们。然后我想对其他用户做同样的事情,产生一个排行榜。我不知道数据库中用户的名称。
下面的查询只产生一个结果,即用户 JOE 的总费率
SELECT SUM(Rate) totalRate FROM tableName WHERE user = 'joe'
这将向用户显示最高费率,因为它是根据 totalRate 降序排序的
SELECT user, SUM(rate) totalRate FROM tableName -- WHERE user = 'JOE' GROUP BY user ORDER BY totalRate DESC