gpt4 book ai didi

mysql - 如何在不使用 UNION 的情况下优化 sql 中的查询

转载 作者:行者123 更新时间:2023-11-29 12:40:26 26 4
gpt4 key购买 nike

我的查询为:

SELECT i.id AS id
FROM table_a i
WHERE (i.cat_id IN (92, 224))
GROUP BY id
HAVING (COUNT(i.cat_id) = 2 AND SUM(i.cat_id) = 316)

UNION
(
SELECT i.id AS id
FROM table_a i
WHERE (i.cat_id IN (92, 227))
GROUP BY id
HAVING (COUNT(i.cat_id) = 2 AND SUM(i.cat_id) = 319)
)

如何优化这个查询?

最佳答案

SELECT i.id AS id
FROM table_a i
WHERE (i.cat_id IN (92, 224) OR i.cat_id IN (92, 227))
GROUP BY id
HAVING (COUNT(i.cat_id) = 2
AND (SUM(i.cat_id) = 316 OR SUM(i.cat_id) = 319 )

关于mysql - 如何在不使用 UNION 的情况下优化 sql 中的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26204301/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com