有什么想法可以优化以下 SQL 查询吗?运行需要相当长的时间。通常大约 3-8 秒,具体取决于它是哪种产品。
SELECT
`serviceid`
FROM
`services`
INNER JOIN `products` ON `serviceid`=products.`id`
WHERE
`orderid` IN
(
SELECT `orderid` FROM `orders_items`,`orders`
WHERE
`orderid`=orders.`id` AND
`status` > '2' AND
`serviceid`='___SYSTEM_VARIABLE___'
)
AND NOT
`serviceid`='___SYSTEM_VARIABLE___' AND
products.`state`='1' AND
products.`stock` > 0
GROUP BY
`serviceid`
ORDER BY
COUNT(`serviceid`) DESC LIMIT 15
谢谢!