自连接
表连接自己,通过某个条件
Id | Name | Salary | ManagerId
----+-------+--------+-----------
1 | Joe | 70000 | 3
2 | Henry | 80000 | 4
3 | Sam | 60000 | NULL
4 | Max | 90000 | NULL
例子:查找收入超过各自经理的员工的姓名
SELECT w1.Id
FROM weather w1
JOIN weather w2
ON DATEDIFF(w1.RecordDate,w2.RecordDate)=1
WHERE w1.Temperature>w2.Temperature
注意:自连接一定要给两张一样的表起不一样的别名
用法:
from table1 as t1,table as t2
from table1 as t1 join table as t2
标签:Temperature,w2,w1,mysql,table,连接
From: https://www.cnblogs.com/hzk20220818/p/16771329.html