怎么统计重复的sum总数

lshfong 2011-09-15 10:20:17
表test结构如下:
id username fs
1 aa 10
2 bb 20
3 cc 10
4 aa 20
5 bb 15
===========================
怎么分组进行统计呢,这样写好象可以分组,但是没有统计,应该怎么样写呢
select id,username,sum(fs) as fs from test GROUP BY username
...全文
86 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
WWWWA 2011-09-15
  • 打赏
  • 举报
回复
select username,min(id),sum(fs) as fs from test GROUP BY username
lshfong 2011-09-15
  • 打赏
  • 举报
回复
统计后的结果如下
id username fs
1 aa 30
2 bb 35
3 cc 10
vipper23 2011-09-15
  • 打赏
  • 举报
回复
mysql> select ifnull(username,'total'),sum(fs) from test group by username with rollup;
+--------------------------+---------+
| ifnull(username,'total') | sum(fs) |
+--------------------------+---------+
| aa | 30 |
| bb | 35 |
| cc | 10 |
| total | 75 |
+--------------------------+---------+
4 rows in set (0.00 sec)


纯属猜测
聪明的一休 2011-09-15
  • 打赏
  • 举报
回复
应该是这个意思吧

SELECT username, sum(fs) AS fs FROM test GROUP BY username
WWWWA 2011-09-15
  • 打赏
  • 举报
回复
select username,sum(fs) as fs from test GROUP BY username
你要达到什么目的?举例说明

56,675

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧