我想不显示我的查询中是否有重复的id_customer,
id_customer firstname lastname email total_paid
--------------------------------------------------------
55 name8 name10 ***@windowslive.com 88.90
58 name6 name7 ****@hotmail.com 78.90
59 name3 name5 ****@hotmail.com 123.83
60 name name2 ****@hotmail.com 78.90
我正在使用" group by"但它并没有显示出来。我希望它不会显示任何东西,甚至
显示如下
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
--------------------------------------------------------
55 name8 name10 ***@windowslive.com 88.90
59 name3 name5 ****@hotmail.com 123.83
60 name name2 ****@hotmail.com 78.90
但我希望看到这样的
Sum(CASE WHEN attempt.result = 0 THEN 0 ELSE 1 END) as Count,
答案 0 :(得分:2)
试试这个:
SELECT
ps_orders.id_customer,
ps_customer.firstname,
ps_customer.lastname,
ps_customer.email,
ps_orders.total_paid
FROM
ps_orders
JOIN ps_customer
on ps_orders.id_customer = ps_customer.id_customer
WHERE
ps_orders.total_paid > 1
AND ps_orders.id_customer IN ( SELECT ps_orders.id_customer
FROM ps_orders
GROUP BY ps_orders.id_customer
HAVING COUNT(1) < 2 )
答案 1 :(得分:1)
您需要检查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
GROUP BY
ps_orders.id_customer
HAVING COUNT(*)=1
:
MyController