我有两张桌子:
Table1
:
RulesVectorID(nullable, primary),Weight,IsDeleted
Table2
:
RulesVectorID(forigen) , Weight,IsDeleted, NumberOfOffers, other fields...
我想做两件事:
分配
Id
给 table1 中的所有行where RulesVectorID ==null
我试过这个:
UPDATE myTable1 SET RulesVectorID = SELECT MAX(RulesVectorID) + 1 FROM myTable1, WHERE RulesVectorID IS NULL
对于在步骤 (1) 中添加的行,我想复制它们的
Weight, IsDeleted
列并将 1 添加到它们的NumberOfOffers
我试过这个:
INSERT INTO myTable2 (Weight, IsDeleted, NumberOfOffers, RulesVectorID) VALUES ( SELECT Weight, IsDeleted, 1, RulesVectorID FROM myTable1 WHERE myTable1.RulesVectorID NOT IN (SELECT RulesVectorID FROM myTable2))
有没有更清洁的方法呢?