假想一条SQL语句,查询19年所有客户的订单总金额

假想写一条SQL语句,查询2019年所有客户的订单总金额,并按总金额从大到小排序。(客户表customer, 订单表orders, 订单明细表orderitem)

第1个回答  2019-08-04
select a.customerid,
a.customername,
sum(c.money) money
from customer a,
orders b,
orderitem c
where a.customerid = b.customerid
and b.orderid = c.orderid
and b.orderdate between '2019-01-01 00:00:00.000' and '2019-12-31 23:59:59.999'
group by a.customerid,
a.customername
order by money desc本回答被提问者采纳
第2个回答  2019-08-04
select 客户名称,sum(订单表金额字段) from 客户表 join 订单表 on 客户表.客户ID = 订单表.客户ID group by 客户表.客户ID;