表A(消费记录) 字段有:id(主键),money(金额),recordDate(记录时间),bid(主B表关联ID)
表B(人员信息)字段有:id(主键),name(姓名),age(年龄),
A表中的信息是每一次的消费记录,B表中是每个人的基本信息
现在想用SQL 查出每个人的消费总数, 查出:B.name ,B.age ,sum(A.money) ,查询条件为 where B.name like '%%'
------解决方案--------------------
- SQL code
select b.name,b.age,sum(a.money) as totalfrom a inner join b on a.bid=b.idwhere b.name like '%%'group by b.name,b.age