【问题标题】:A query to get list of records whose ids exist in another table but with a different value for other column用于获取其 id 存在于另一个表中但其他列具有不同值的记录列表的查询
【发布时间】:2013-11-25 20:57:33
【问题描述】:

我有两张结构相同的表(一张用于 2012 年,一张用于 2013 年),都包含人员详细信息及其工作 ID。我正在寻找所有获得晋升的人的名单。我知道一个人只有在 2012 表中存在其人员 ID 但职位 ID 已更改时才能获得晋升。我知道我可以使用 exists 并获取 2012 表中的所有记录,但是如何检查两个表中的记录应该具有不同的位置 ID 值这一事实?

表 1 和 2:

pers_id、姓名、部门、​​薪水、工作编号.....

【问题讨论】:

    标签: sql ms-access ms-access-2013


    【解决方案1】:
    SELECT t2.*
    FROM table2012 t1
    INNER JOIN table2013 t2 ON t1.tableID = t2.tableID
    WHERE t1.position <> t2.position;
    

    tableId 是表中每条记录的标识符。我不确定那是 pers_id 还是您有不同的 id。

    【讨论】:

    • Access 使用!= 抛出语法错误,因此将WHERE 条件更改为t1.position &lt;&gt; t2.position
    【解决方案2】:
    SELECT Data2013.pers_id
    FROM Data2013 INNER JOIN Data2012
      ON (Data2013.pers_id = Data2012.pers_id) AND (Data2013.position_id <> Data2012.position_id);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-14
      • 2018-07-13
      • 1970-01-01
      • 2022-01-21
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多