文章详情页
mysql sum去除重复
浏览:168日期:2022-06-20 11:32:53
问题描述
A表
id name price1 a 12 b 1
B表
id type1hh1hh2ccselect sum(price) from A as a left join B as b on a.id=b.id where b.type=hh返回结果2,现在我想根据A表id(distinct)统计,得出sum(price)为1的sql语句怎么写?
问题解答
回答1:B表两条id为1的记录,left join查询会得到两条记录并求和,所以就为2了,你在B表中删除一条id为1的数据,应该就对了。但是问题并没有解决,可以这样:
select sum(price) from A as a left join (select id,type from B group by id) as temp on a.id=temp.id where temp.type=hh
由于没有任何开发环境,没法测试,大致就这样吧。
上一条:mysql - Access denied for user ’ODBC’@’localhost’ (using password: NO)下一条:mysql - 如何联合查询两个结构相同的表并且id不重复
相关文章:
1. html5 - html img 标签 为什么会出现 image for resizing2. 多维数组遍历,求大佬解答???3. javascript - swiper2索引的问题4. python3.x - python连oanda的模拟交易api获取json问题第五问5. javascript - 关于vue-cli每次都要build才能放到线上问题。6. 使用未定义的常量user_id-假定为“user_id”7. javascript - 怎么获取一个页面中的所数据,然后弄成一个json格式的字符串传给后台8. 大兄弟们,你们都用什么框架开发 web app9. javascript - webpack异步加载js问题10. python方法调用
排行榜

网公网安备