2个表之间的不同连接
Distinct join between 2 tables
这是我的代码:
SELECT DISTINCT Emps.name, Degrees.Name AS 学位, Degrees.Date AS degree_date
来自 Emps INNER JOIN
开度 Emps.id = Degrees.empId
但是 distict 不起作用,我想要这个结果
我想要具有最大 ID 或最大日期的学位的地区名称
感谢所有我找到了解决方案
SELECT e.name, d.Name AS degree
FROM Emps AS e
full JOIN (
SELECT t.*, ROW_NUMBER() OVER (PARTITION BY t.empId ORDER BY t.id DESC) AS rn FROM Degrees AS t
) AS d ON e.id = d.empId
WHERE d.rn = 1
这是我的代码:
SELECT DISTINCT Emps.name, Degrees.Name AS 学位, Degrees.Date AS degree_date
来自 Emps INNER JOIN
开度 Emps.id = Degrees.empId
但是 distict 不起作用,我想要这个结果
我想要具有最大 ID 或最大日期的学位的地区名称
感谢所有我找到了解决方案
SELECT e.name, d.Name AS degree
FROM Emps AS e
full JOIN (
SELECT t.*, ROW_NUMBER() OVER (PARTITION BY t.empId ORDER BY t.id DESC) AS rn FROM Degrees AS t
) AS d ON e.id = d.empId
WHERE d.rn = 1