【问题标题】:error in inner join function内连接函数错误
【发布时间】:2015-10-06 13:49:25
【问题描述】:

我目前有一个表格(示例快照):

Employee ID Old Value      New Value         Update Date

1           Analyst        non-employee     10/1/2012

1           non-employee   Senior Analyst   10/1/2012

2           Analyst        non-employee      9/1/2012

2           non-employee   Assistant Mgr.    9/1/2012

2           Assistant Mgr. non-employee     10/1/2015

2           non-employee   Manager          10/1/2015

3           Analyst        non-employee     10/1/2015

3           non-employee     Manager          10/1/2015

4           Analyst        non-employee      9/1/2012

4           non-employee   Senior Analyst    9/1/2012

4           Senior Analyst non-employee     10/1/2015

4           non-employee   Assistant Mgr.   10/1/2015

4           Assistant Mgr. non-employee     10/6/2015

4           non-employee   Manager          10/6/2015

从这个表中,我需要挑选出那些直接从分析师转变为经理的员工 ID,即无需成为助理经理或高级分析师。

期望的结果:

Employee ID Old Value   New Value   Update Date

3           Analyst     Manager     10/1/2015

我在 access 中运行了以下查询以获得所需的结果:

select t.id, t.oldvalue, tnext.newvalue, t.updatedate
from table t inner join
     table tnext
     on t.employeeid = tnext.employeeid and
        t.updatedate = tnext.updatedate and
        t.newvalue = 'non-employee' and
        tnext.oldvalue = 'non-employee'
where t.oldvalue = 'Analyst' and tnext.newvalue = 'Manager';

我收到错误,因为查询的 t.newvalue='non-employee' 部分突出显示了 Join 表达式。我用谷歌搜索了这个问题,但我无法找出问题所在。任何帮助将非常感激!谢谢!

【问题讨论】:

    标签: mysql inner-join


    【解决方案1】:

    在加入条件下,尝试改变

    tnext.oldvalue = '非雇员'

    tnext.oldvalue = '非会员'

    我认为这应该可以解决您的问题。

    【讨论】:

    • 对表格中的错字表示歉意。应该是非员工。每当发生变化时,状态首先会更改为非员工状态,然后再更改为新状态。
    • 我刚刚对 sqlite 数据库中的相同关系运行了相同的查询并得到了完美的结果。您使用的是什么 DBMS?
    • 我正在使用 MS Access。不幸的是,这是我目前拥有的唯一软件。
    • 您能否尝试将表达式 t.newvalue = 'non-employee' and tnext.oldvalue = 'non-employee'join 条件转移到 where 子句。我正在查看 msdn 文档 msdn.microsoft.com/EN-US/library/office/ff197346.aspx#Anchor_0,但我认为他们不允许这样做。不过不确定。
    • 我做到了。但在这种情况下,Access 会提示我输入所有字段的详细信息。
    【解决方案2】:

    感谢各位的帮助...我想我找到了问题所在。我必须以 MS Access “可接受”的格式编写查询。 我写了这个查询并且它有效:

    选择 a1.uid、a1.oldvalue、a2.newvalue、a1.updatedate

    FROM Table1 AS a1 INNER JOIN

    (Select Table1.uid, Table1.oldvalue, Table1.newvalue, Table1.updatedate FROM Table1 where Table1.oldvalue="Non-Employee" AND Table1.newvalue="Manager") AS a2

    开启(a1.updatedate = a2.updatedate)和(a1.uid = a2.uid)

    WHERE (((a1.oldvalue)="Analyst") AND ((a1.newvalue)="Non-Employee"));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 2018-02-13
      • 2012-10-02
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多