customer id name Pay_type
1111 aaaa regular
1111 aaaa late
1111 aaaa regular
1111 aaaa regular
2222 bbbb regular
2222 bbbb regular
2222 bbbb regular
3333 cccc regular
3333 cccc late
4444 dddd regular
4444 dddd regular
我有一个提供上述结果的SQL查询,我希望该结果删除所有有滞纳金的客户
输出必须为:
customer id name Pay_type
2222 bbbb regular
2222 bbbb regular
2222 bbbb regular
4444 dddd regular
4444 dddd regular
select
distinct a.customer_id,
a.name,
pay_type
from table a
left join table b on a.customer_id= b.id
left join table c on c.id = b.pay_id
where b.status = 'Done
答案 0 :(得分:0)
我不确定您的表格到底是什么样子,但是您可以执行以下操作:
WHERE customer_id NOT IN (
SELECT customer_id
FROM table_with_customer_and_pay_type
WHERE pay_type = 'late'
GROUP BY customer_id )
答案 1 :(得分:0)
我会以此为反对:
select *
from table a
where not exists (
select null
from table b
where
a.customer_id = b.customer_id and
b.pay_type = 'late'
)
与独特或“不在”的方法相比,它具有优势,因为它将在找到匹配项后停止寻找。这对于大型和小型数据集都应有效。
任何使用distinct的解决方案都必须评估整个数据集,然后删除重复项。
答案 2 :(得分:0)
公用表表达式的变化形式:
.slide-active {
color: green;
}