我在尝试选择和删除时遇到此问题。你能帮我解决这个问题吗?
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)
答案 0 :(得分:18)
你可以用这样的子查询来做到这一点
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 )