请教一条SUM的查询语句 表格字段结构如下: ID Name Value表中存在相同ID的多笔记录,现在是希望能够查询出 所有 相同ID的 Value数的 求和谢谢大家! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 table : testid name value0 xixi 101 hehe 111 hehe 132 wuwu 90 xixi 100需要的结果如下:0 xixi 1101 hehe 242 wuwu 9谢谢大家! select id,name,sum(value) from test group by id,name 谢谢ACMain_CHM的指点现在还有个需求,就是在上面的基础上,还有另外一张表table : contextid desc0 one0 two1 oneone2 twotwo需要能够根据上面数据排序后的id,检索出context表格中的desc信息 需要的结果如下:0 xixi one 1100 xixi two 1101 hehe oneone 242 wuwu twotwo 9 恩,谢谢ACMAIN_CHM提醒,下次改正,刚开始学SQL 呵呵,还不熟悉 select c.*,b.value from context c left join (select id,name,sum(value) value from test group by id,name) t on c.id = t.id; select b.id,b.name,c.desc,b.value value from context c left join (select id,name,sum(value) value from test group by id,name) t on c.id = t.id; mysql 的compute 预处理嵌套游标无效!!!大神请进 关于mysql存储过程 cursor 如何根据某列数值输出TOP n的数据,着急。今天内要解决! 如何只接收mysql中的一条记录? 请大虾推荐基本经典的MYSQL教程! 怎么更改列名? 一个简单的左连接sql语句,请帮忙!!! 建立一个C/S模式的应用,server端是否可以使用国外的某些免费空间?比如一些支持php/mysql的空间? mysql 联表查询效率问题 一個社交網站,如果要快速查找信息,索引及sql要如何設定? 又是Mysql乱码的问题!
id name value
0 xixi 10
1 hehe 11
1 hehe 13
2 wuwu 9
0 xixi 100需要的结果如下:
0 xixi 110
1 hehe 24
2 wuwu 9谢谢大家!
table : context
id desc
0 one
0 two
1 oneone
2 twotwo需要能够根据上面数据排序后的id,检索出context表格中的desc信息
0 xixi one 110
0 xixi two 110
1 hehe oneone 24
2 wuwu twotwo 9
left join
(select id,name,sum(value) value from test group by id,name) t
on c.id = t.id;
left join
(select id,name,sum(value) value from test group by id,name) t
on c.id = t.id;