所以,我有两张桌子--桌子顾客和桌子订单。customer with attributes custid, name, address和orders with attributes customerid, orderid, date and status.我需要返回那些客户的I,他们的订单中有超过15%的订单处于“失败”状态。
这是我写的,但目前不起作用的是:
SELECT C.custid
FROM customers C
WHERE C.custid IN (SELECT O.customerid, COUNT(status)
FROM orders O
WHERE O.status='failed'
GROUP BY O.custid
HAVING COUNT(status)=0.15)发布于 2018-11-01 09:43:25
下面是在orders表上使用聚合的一种方法:
SELECT customterid
FROM orders
GROUP BY customerid
HAVING COUNT(CASE WHEN status = 'failed' THEN 1 END) / COUNT(*) > 0.15;https://stackoverflow.com/questions/53098601
复制相似问题