简体   繁体   中英

IN Clause Hangs PHPmyadmin - Mysql

I have 2 queries, first query

SELECT DISTINCT( timesheetemployeeid ) AS USER_ID 
FROM   timesheet 
WHERE  timesheetemployeeid != '' 
       AND ( timesheetemployeeconfirm = 1 
              OR ( timesheetemployerconfirm = 1 
                   AND ( timesheetdispute = 0 
                          OR timesheetdispute IS NULL ) ) ) 
       AND timesheetemployerremove IS NULL 
       AND ` timesheetdate ` BETWEEN '2018- 05-27' AND '2018-06-02' 
       AND office_id = 8 
       AND timesheetremove IS NULL 
       AND adminnotconfirmed = 0 
       AND timesheet_id NOT IN (SELECT parenttimesheet_id 
                                FROM   timesheet 
                                WHERE  timesheetemployeeid != '' 
                                       AND timesheetdate BETWEEN 
                                           '2018-05-27' AND '2018-06-02' 
                                       AND ( timesheetemployeeconfirm = 1 
                                              OR ( timesheetemployerconfirm = 1 
                                                   AND ( timesheetdispute = 0 
                                                          OR timesheetdispute IS 
                                                             NULL ) 
                                                 ) ) 
                                       AND timesheetemployerremove IS NULL 
                                       AND timesheetremove IS NULL 
                                       AND office_id = 8 
                                       AND ( parenttimesheet_id IS NOT NULL 
                                              OR parenttimesheet_id != '' )) 
UNION ALL 
SELECT DISTINCT( employee ) AS Employee 
FROM   workordercurrent 
WHERE  employee != '' 
       AND office_id = '8' 
       AND schedulestopdate >= '2018-05-27' 
       AND schedulestopdate <= '2018-06- 02' 

returns USER_ID with 200 recrods in 0.1047 seconds
在此处输入图片说明

Second Query returns Prodpay in 0.2834 seconds

    SELECT Sum(pay) AS ProdPay 
FROM   (SELECT currentrate * lineitemquantity AS Pay 
        FROM   (SELECT B.currentworkorder_id, 
                       D.lineitems_lineitemid, 
                       D.lineitemquantity, 
                       C.currentrate, 
                       C.currenteffectivedate 
                FROM   payscaleslocal A 
                       JOIN workordercurrent B 
                         ON A.worktype = B.worktype 
                            AND A.workarea = B.workarea 
                       JOIN payscaleloacljobcodes C 
                         ON A.payscaleslocal_id = C.payscaleslocal_id 
                       JOIN workorderlineitems D 
                         ON C.jobcodeid = D.lineitems_lineitemid 
                            AND 
               B.currentworkorder_id = D.workordercurrent_workorderid 
                WHERE  A.payscale = '16' 
                       AND B.employee = '1287' 
                       AND B.office_id = '8' 
                       AND B.schedulestopdate = '2018-05-27' 
                       AND ( B.orderstatus = 2 
                              OR B.orderstatus = 3 ) 
                       AND C.currenteffectivedate <= '2018-05-27' 
                ORDER  BY C.currenteffectivedate DESC) M 
        GROUP  BY lineitems_lineitemid, 
                  currentworkorder_id) K 

在此处输入图片说明

I am trying to join these 2 queries using the IN Clause

So in the second Query - I tried changing the B.Employee IN (<Results of the first query>)

The problem is, the Query keeps on loading and does not show any results for 5 mins, I have to close phpmyadmin and restart it again.

I am trying to show user_id in the first column and respective prodpay of that user_id in the second column, by joining these 2 queries

Create a temp table based on the first query. Index timesheetemployeeid And then run the IN on that table. Drop the table after the queries run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM