SQLite:UPDATE JOIN子查询的替代方法

时间:2017-02-06 22:48:48

标签: sqlite

我在SQLite中有以下SELECT查询。我正在努力弄清楚如何将其转换为SQLite友好的UPDATE语句,但我知道SQLite UPDATE不支持JOIN。谢谢!

查询正在查找每位员工的最近/最长日期,并向每位员工添加包含该日期的列

SELECT
  emp.*, maxdate
FROM
  employees emp JOIN (
    SELECT name as newname, MAX(enddate) AS maxdate
    FROM
      employees
    GROUP BY name) m
  ON emp.name = m.newname
  ORDER BY maxdate DESC;

1 个答案:

答案 0 :(得分:1)

嗯,如果我理解正确,你想要的是

UPDATE employees
        SET enddate = (
             SELECT MAX(enddate)
                  FROM employees e2
                  WHERE e2.name = employees.name
             );