gpt4 book ai didi

mysql - 使用几乎相同的子查询优化 mySQL 查询

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

有没有办法优化以下查询?

SELECT s1.* FROM
(SELECT s.*
FROM answer a, answer_item ai, sessions s
WHERE s.session_state='FINISHED' AND a.sessionId=s.id AND ai.answer=a.id
AND a.question=1001 AND ai.question_variant_id=1103) s1,
(SELECT s.*
FROM answer a, answer_item ai, sessions s
WHERE s.session_state='FINISHED' AND a.sessionId=s.id AND ai.answer=a.id
AND a.question=1003 AND ai.question_variant_id=1301) s2
WHERE s1.id=s2.id

除了这些部分之外,一切似乎都是一样的:

  1. a.question=1001 AND ai.question_variant_id=1103
  2. a.question=1003 AND ai.question_variant_id=1301

最佳答案

SELECT s.* 
FROM answer a
JOIN answer_item ai ON ai.answer=a.id
JOIN sessions s ON a.sessionId=s.id
WHERE s.session_state='FINISHED'
AND
(
a.question=1001 AND ai.question_variant_id=1103
OR a.question=1003 AND ai.question_variant_id=1301
)

关于mysql - 使用几乎相同的子查询优化 mySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26799700/

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