Mysql - Sql 查询和过滤

Mysql - Sql Query sum and filter

我只想显示总订单大于 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
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