id | username | salary | pid |
---|---|---|---|
1 | a | 3000 | null |
2 | b | 8000 | null |
3 | c | 5000 | 1 |
4 | d | 6000 | 3 |
SELECT a.*, b.*
FROM `user` as a
LEFT JOIN `user` as b ON a.pid = b.id AND a.salary > b.salary
WHERE b.id > 0;
原文:https://www.cnblogs.com/yszr/p/10520489.html