假设我有一些这样的数据(日期类型的东西,月/日/年/标志/用户列)
1 - 1 - 2013 flag:1 user:123456
1 - 2 - 2013 flag:0 user:123456
1 - 3 - 2013 flag:0 user:123456
1 - 4 - 2013 flag:0 user:123456
1 - 5 - 2013 flag:1 user:123456
3 - 1 - 2013 flag:1 user:987654
3 - 2 - 2013 flag:0 user:987654
3 - 3 - 2013 flag:0 user:987654
3 - 4 - 2013 flag:0 user:987654
3 - 5 - 2013 flag:1 user:987654
我想从用户 123456 中删除除第一条记录之外的所有记录。我试过:
DELETE FROM table
WHERE year = 2013
AND user = 123456
AND (month != 1 AND day != 1 AND year != 2013 AND flag != 1)
国旗很重要。我很难过。我试过 NOT IN 这样的:
DELETE
FROM table
WHERE year = 2013
AND user = 123456
NOT IN (SELECT *
FROM table
WHERE month = 1 AND day = 1 AND year = 2013 AND flag = 1)
但我不能不上班。我究竟做错了什么?