mysql 两表结果集取差集:
示例:
SELECT r1.* FROM
(SELECT r.USER_ID FROM rocky_b_repaymentrecord r,rocky_borrow b WHERE r.BORROW_ID = b.ID AND r.`STATUS` = 1 AND b.BORROWTYPE = 2 GROUP BY r.USER_ID) r1
LEFT JOIN (SELECT r.USER_ID FROM rocky_b_repaymentrecord r,rocky_borrow b WHERE r.BORROW_ID = b.ID AND r.`STATUS` = 0 AND b.BORROWTYPE = 2 GROUP BY r.USER_ID) r2 on(r1.USER_ID = r2.USER_ID)
WHERE r2.USER_ID IS NULL;
说明:表1和表2根据user_id取表1-表2的差集。
版权声明:本文为yangshijin1988原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。