SELECT EVENTTIME,LOTNO,EQUIPMENTNO,XH FROM ( SELECT T1.EVENTTIME,T1.LOTNO,T2.EQUIPMENTNO, ROW_NUMBER() OVER (PARTITION BY T2.EQUIPMENTNO ORDER BY T1.EVENTTIME) AS XH FROM tblWIPLotState T1 INNER JOIN tblWIPDispatchstate T2 ON T1.LOTNO=T2.LOTNO WHERE T1.STATUS=0 ) A WHERE XH=1 |