这是我的表
loan_id bid_id lender_id borrower_id 金额 兴趣 持续时间 loan_status
1 1 60 63 300.00 12.00 3 'completed'
2 2 61 63 300.00 12.00 3 'completed'
3 3 62 63 300.00 12.00 3 'pending',
4 1 62 63 300.00 12.00 3 'pending'
7 4 60 63 300.00 12.00 3 'completed'
我想只提取所有记录的loan_status 已完成的bid_id。这意味着,如果 bid_id 的记录状态为待处理,那么它将不会提取该记录。
我正在使用正常运行的followin查询:
SELECT bid_id
FROM loan
WHERE bid_id NOT IN (
SELECT l.bid_id
FROM loan l
WHERE l.`loan_status` = 'pending'
AND l.bid_id = bid_id
GROUP BY l.`bid_id`
HAVING COUNT(l.`bid_id`)>= 1
)
GROUP BY bid_id
有没有其他方法可以在不使用子查询的情况下获得所需的结果。
答案 0 :(得分:2)
您可以使用group by
和having
:
select bid_id
from loan
group by bid_id
having sum(loand_status = 'pending') = 0