Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
仅使用一个 MYSQL 查询,我如何检查买家和卖家是否都相互购买?
表:购买
purchase_id | seller | buyer 12 | 2 | 5 29 | 5 | 2
如果查询返回一个结果(这里就是这种情况),那么页面上就会出现一个特定的 div。
SELECT (COUNT(*) >= 2) AS Result FROM purchase a INNER JOIN purchase b ON a.seller = b.buyer AND a.buyer = b.seller WHERE (a.seller = 2 AND a.buyer = 5) OR (a.seller = 5 AND a.buyer = 2)
只需用你的变量替换2和。5
2
5