【问题标题】:How to get two separate result with single query如何使用单个查询获得两个单独的结果
【发布时间】:2014-06-23 18:51:11
【问题描述】:

我的目标是得到每个人的总分,并返回用户名和他/她的总分。

id      |   username  |   points

1           Michelle       23
2           Chester        44
3           Michelle       13
4           Chester        23
5           Chester        65
6           Chester        43
7           Michelle       65
8           Chester        12
9           Michelle       54
10          Chester        76

想要的结果

username   |  total_points

Chester    |  total points of Chester
Michelle   |  total points of Michelle

【问题讨论】:

  • GROUP BY 用户名,对点求和,从查询中删除 ID。

标签: php mysql sql sum


【解决方案1】:

怎么样:

SELECT      username, SUM(points) total_points
FROM        mytable
GROUP BY    username
ORDER BY    username

【讨论】:

    猜你喜欢
    • 2011-08-19
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-03
    • 2013-04-28
    相关资源
    最近更新 更多