0
任何人都可以幫助我優化此查詢。我無法執行它,因爲phpMyAdmin連接超時,我無法更改超時參數。優化MySQL查詢,因爲它會超時
下面是一個查詢:
INSERT INTO `goods` (`goods_id`, `price`, `name`)
SELECT `sales_goods`.`goods_id`, `sales_goods`.`price`, `sales_goods`.`goods_id`
FROM `sales_goods`
WHERE `sales_goods`.`sales_goods_id`
IN (
SELECT MAX(`sales_goods`.`sales_goods_id`)
FROM `sales_goods`
WHERE `sales_goods`.`sales_goods_id`
IN (
SELECT `sales_goods`.`sales_goods_id` FROM `sales_goods`
WHERE `sales_goods`.`goods_id` NOT IN (SELECT `goods`.`goods_id` FROM `goods`)
)
GROUP BY `sales_goods`.`goods_id`
)
避免IN子句它是性能殺手...我的意思是嘗試將查詢更改爲JOINS而不是嵌套INs – 2013-04-25 10:25:17
即使在翻譯來自立陶宛語的查詢之後,它有點h想知道你想做什麼... – 2013-04-25 10:29:15
我同意,我無法理解它 - 我想我知道..但是這個MAX?!? @ user2319233試圖解釋你的目標 – 2013-04-25 10:41:26