MySQL JOIN查询崩溃

时间:2018-08-01 17:41:52

标签: mysql

我对查询中DBMS的行为感到非常困惑,这就是为什么我需要一些帮助。

我有3个不同的表格:

 T1 org_info  (routing , job_id)
 VALUES ('|1111|2222|','1300');

 T2 aff_info  (job_id , employee_id , dbegin)
 VALUES('1300','0153','10/02/2017');

 T3 pers_info (employee_id , name)
 VALUES('0153','Gates');

post_info表保留了有关谁在工作的每条记录,因此我的查询目的是获取最近担任此工作的人。

这是我的查询:

SELECT distinct a.employee_id   AS Mat, 
                o.routing       AS Routing,
                o.job_id        AS Job,
                p.last_name     AS Name,
                a.job_id        AS Job2,
                a.dbegin        AS Date_begin
                FROM org_info o

                INNER JOIN aff_info a
                ON o.job_id = a.job_id

                INNER JOIN(
                SELECT MAX(dbegin_post) AS dmax, job_id
                FROM aff_info 
                GROUP BY job_id) b
                ON a.job_id = b.job_id

                INNER JOIN pers_info p
                ON a.employee_id = p.employee_id

                WHERE a.dbegin = dmax
                AND o.routing LIKE '%2222%'
                AND a.job_id= 1300 <!-- Works only with this parameter-->

如果我删除了最后一个参数,它将因以下错误而崩溃:

  

查询执行被中断

我希望*这次清楚地解释一下:)

谢谢

0 个答案:

没有答案