gpt4 book ai didi

mysql - 是否可以优化我的查询?

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

(你可以更好地阅读here)

我想知道是否可以优化此查询:

SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p1 AND id_action_set = 1
UNION ALL
SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p2 AND id_action_set = 1
UNION ALL
SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p3 AND id_action_set = 1
UNION ALL
SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p4 AND id_action_set = 1
UNION ALL
SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p5 AND id_action_set = 1
UNION ALL
SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p6 AND id_action_set = 1
UNION ALL
SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p7 AND id_action_set = 1
UNION ALL
SELECT id_type, value FROM Action, Action_set WHERE id_action = id_action_p8 AND id_action_set = 1

最佳答案

尝试:

SELECT id_type, value 
FROM Action, Action_set
WHERE id_action IN (id_action_p1,id_action_p2,id_action_p3,id_action_p4,id_action_p5,id_action_p6,id_action_p7,id_action_p8)
AND id_action_set = 1

如果多于一行尝试:

SELECT id_type, value 
FROM Action, Action_set
WHERE (id_action = id_action_p1
OR id_action = id_action_p2
OR id_action = id_action_p3
OR id_action = id_action_p4
OR id_action = id_action_p5
OR id_action = id_action_p6
OR id_action = id_action_p7
OR id_action = id_action_p8)
AND id_action_set = 1

关于mysql - 是否可以优化我的查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11122450/

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