我想只显示我的查询,只是总订单大于200
现在我的查询是
SELECT
ps_orders.id_customer,
ps_customer.firstname,
ps_customer.lastname,
ps_customer.email,
ps_orders.total_paid
FROM
ps_orders
RIGHT JOIN ps_customer
on ps_orders.id_customer = ps_customer.id_customer
WHERE
ps_orders.total_paid > 1
ORDER BY
ps_orders.id_customer;
显示如下
id_customer firstname lastname email total_paid
--------------------------------------------------------
55 name8 name10 ***@windowslive.com 88.90
58 name6 name7 ****@hotmail.com 56.00
58 name6 name7 ****@hotmail.com 87.90
58 name6 name7 ****@hotmail.com 79.99
58 name6 name7 ****@hotmail.com 78.90
59 name3 name5 ****@hotmail.com 123.83
60 name name2 ****@hotmail.com 78.90
我想要这样的节目
id_customer firstname lastname email total_paid
--------------------------------------------------------
58 name6 name7 ****@hotmail.com 302.49
答案 0 :(得分:2)
Group by ps_orders.id_customer having sum(ps_orders.total_paid) > 200
«分组»将您的数据分组并将该组的总和
编辑:«where»无法进行聚合功能。
SELECT ps_orders.id_customer,
ps_customer.firstname,
ps_customer.lastname,
ps_customer.email,
sum(ps_orders.total_paid) as totalOrder
....... 按ps_orders.id_customer,ps_customer.firstname,ps_customer.lastname,ps_customer.email分组,其总和(ps_orders.total_paid)> 200