INSERT INTO user_week_rate UserID YEAR WEEK ROI SELECT ID 2014 23 FROM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
INSERT INTO user_week_rate (UserID, YEAR, WEEK, ROI)
SELECT u.ID, 2014, 23, 0
FROM Users u
WHERE
u.AccountState = 0 AND
u.ID NOT IN (
SELECT ID
FROM user_week_rate r
WHERE r.Year = 2014 AND r.Week = 23);
SELECT *
FROM user_week_rate; ROLLBACK;