这是典型的聚合查询。
创新互联专注于企业营销型网站建设、网站重做改版、潮南网站定制设计、自适应品牌网站建设、H5响应式网站、商城网站开发、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为潮南等各大城市提供网站开发制作服务。
假设第一个表的三个字段名分别为 P1, P2 , P3
select p1, p2, sum(p3) from table group by p1,p2
题主这个问题可以通过以idz和a这两个字段分组汇总获得。下面是具体的sql语句供参考:
select a,sum(b) as totalQty
from tblName where idz=10
group by idz,a;
注意idz如果不是数字则筛选10要对其加单引号
1、创建三张测试表,
create table pw_memberinfo(uid int, name varchar(20));
create table pw_members(companyid int, uid int);
create table pw_memberdata(uid int, deposit int, ddeposit int, money int);
2、三张表,分别插入测试数据,
insert into pw_members values(1, 1);
insert into pw_members values(1, 2);
insert into pw_members values(1, 3);
insert into pw_memberinfo values(1, 'name_1');
insert into pw_memberinfo values(2, 'name_2');
insert into pw_memberinfo values(3, 'name_3');
insert into pw_memberdata values(1,30,50,150);
insert into pw_memberdata values(2,77,50,12);
insert into pw_memberdata values(3,44,50,82);
3、查看pw_memberdata表中的记录,select * from pw_memberdata t,
4、编写sql语句,
select * from (SELECT i.uid, sum(deposit+ddeposit+money) as allmoney
FROM pw_memberinfo i
LEFT JOIN pw_members m ON m.uid=i.uid
LEFT JOIN pw_memberdata d ON i.uid=d.uid
group by i.uid
) t where allmoney200