【问题标题】:Total up MySQL Data?汇总 MySQL 数据?
【发布时间】:2011-07-16 12:12:06
【问题描述】:

我正在为我正在制作的网站制作个人资料页面,其中有一个显示“总评分”的部分,我拥有的数据库结构是

username|song_id|plus|minus
---------------------------
example | 294398|001 | 000
egnum2! | 244202|000 | 001

所以我需要计算包含指定用户名的行数并将它们相加,我找不到我可以很容易理解的 MySQL 命令:S

例如,我访问 example 的个人资料,它会计算他的名字出现在上面 table example 中的所有次数,并给我一个数字,在上面的 example 中,example 有 1 total rate by 'example' in the same方式,我将不得不做另一个我计算他所有的正利率和负利率。 (这些是 1/0,我输入了三位数,因为它不适合大声笑)

【问题讨论】:

    标签: php mysql count add profile


    【解决方案1】:

    使用GROUP BY 查询和aggregate functions

    select username, count(*), sum(plus), sum(minus)
    from your_table
    where username = 'example'
    group by username;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-05
      • 2018-04-23
      • 2017-01-19
      • 2018-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      相关资源
      最近更新 更多