1、原开窗语句
Select distinct TC001,TC002,TC003,TC004,MA002,TC012,TC005,TC006
from COPTC
inner join COPTD ON TD001=TC001 AND TD002=TC002 AND TD016='N'
Left join CMSMQ on TC001=MQ001
Left join CMSMU on MQ001=MU001 and MQ003=MU002
LEFT JOIN COPMA ON TC004=MA001
Where TC027='Y' and (( MU003='wuhy' and MQ029='Y' ) or MQ029='N' )
AND TC050 IN ('Y','N','n')
2、修改后开窗语句
SELECT TOP 100 TC001,TC002,TC003,TC004,MA002,TC012,TC005,TC006
FROM $$COPTC AS COPTC LEFT JOIN $$COPMA AS COPMA ON TC004=MA001
Left join $$CMSMQ AS CMSMQ on TC001=MQ001
Left join $$CMSMU AS CMSMU on MQ001=MU001 and MQ003=MU002
WHERE TC027='Y' AND (( MU003='wuhy' and MQ029='Y' ) or MQ029='N' )
AND TC050 IN ('Y','N','n')
AND EXISTS (SELECT TD001,TD002 FROM $$COPTD WHERE TC001=TD001 AND TC002=TD002 AND TD016='N')