内部左联接上的更新列

时间:2019-02-05 12:03:08

标签: mysql sql

我无法弄清楚如何对该查询进行内部左联接更新(这是选择查询有效):

SELECT
    *
FROM
    emr AS e
    LEFT JOIN visit_ltnot AS v ON e.guid = v._pn
WHERE
    closedate='12-31-79' AND pat='00000906' AND apptstatus=''
    AND v.pdate='' AND emrdate <= '2013-11-26';

我需要更新emr表上的Closedate。

我绑定了以下查询:

UPDATE emr
FROM
    emr AS e
    LEFT JOIN visit_ltnot AS v ON e.guid = v._pn SET closedate=''
WHERE
    closedate='12-31-79' AND pat='00000906' AND apptstatus=''
    AND v.pdate='' AND emrdate <= '2013-11-26';

UPDATE emr
    SET closedate=''
FROM
    emr AS e
    LEFT JOIN visit_ltnot AS v ON e.guid = v._pn
WHERE
    closedate='12-31-79' AND pat='00000906' AND apptstatus=''
    AND v.pdate='' AND emrdate <= '2013-11-26';

我遇到语法错误,我需要更新closedate值。

1 个答案:

答案 0 :(得分:1)

如果您使用的是MySQL,则应该可以使用:

didUpdate

注意:

  • 最重要的是,UPDATE emr e LEFT JOIN visit_ltnot v ON e.guid = v._pn SET closedate = '' WHERE closedate = '12-31-79' AND pat = '00000906' AND apptstatus = '' AND v.pdate = '' AND emrdate <= '2013-11-26'; 在MySQL中没有UPDATE子句。
  • 条件FROM正在将外部联接变为内部联接。因此,您不妨使用v.pdate
  • 您不应使用inner join之类的日期格式。正确的日期格式为'12-31-79'
  • 日期不应存储为字符串,因此'1979-12-31'没有意义。