5

我在尝试选择和删除时遇到了这个问题。你们能帮我解决这个问题吗?

SELECT `danyel_site`.`server_week`.* FROM `server_week` WHERE `weekly` = 0 AND `time` NOT IN (SELECT * FROM `server_week` WHERE `weekly` = 0 ORDER BY `time` DESC LIMIT 10)

我也想用删除

DELETE FROM `server_week` WHERE `weekly` = 0 AND `time` NOT IN (SELECT * FROM `server_week` WHERE `weekly` = 0 ORDER BY `time` DESC LIMIT 10)
4

1 回答 1

19

你可以用这样的子查询来做到这一点

DELETE FROM `server_week` WHERE `weekly` = 0 AND `time` NOT IN 
           (select `time` from ( 
                               SELECT `time` FROM `server_week` 
                                WHERE `weekly` = 0 
                                ORDER BY `time` DESC 
                                LIMIT 10) t ) 
于 2013-10-13T10:27:55.193 回答