我有两张桌子T1和amp; T2
T1 has ID, Sl_No and Active (1, 123, 'Y')
T2 has ID, Sl_No, tDate and OutYesOrNo (1, 123, tdate(CURDATE()), 'Y')
T1是主表。我想将T1中的Sl_No插入T2,其中T1.Active ='Y'和T2.OutYesorNo<> 'Y'和T2.tDate不存在。
我尝试了这个,但它无法正常工作
INSERT INTO T2 (Sl_No)
SELECT Sl_No FROM T1
WHERE (T1. Active = 'Y' OR T1.Active = 'y')
AND NOT EXISTS (SELECT Sl_No From T2 WHERE tDate = CURDATE()
AND T2.OutYesorNo='Y' OR T1.OutYesorNo = 'y')