gpt4 book ai didi

mysql - 我怎样才能合并连接?

转载 作者:行者123 更新时间:2023-11-29 18:11:34 25 4
gpt4 key购买 nike

我有以下有效的查询,但我想改进(性能方面):

.sentence_id 和 .project_id 是索引。

我现在的目标是尝试将同一表上的 2 个联接合并为一个联接(如果可能)我怎样才能做到这一点?

SELECT rs.project_id,
ms.id AS raw_sentence_id,
rs.sentence AS raw_sentence_text,
rs.sentence_id AS raw_sentence_text_id,
rst.tokens AS tokenization_information,
ns.sentence_id AS normalized_sentence_id,
ns.sentence AS normalized_sentence_text,
nst.token_indices
FROM manual_sentences ms
JOIN sentences rs ON (ms.original_sentence_id = rs.sentence_id AND rs.project_id = 623483)
LEFT JOIN sentence_tokens rst ON (ms.original_sentence_id = rst.sentence_id AND rst.project_id = 623483)
JOIN sentences ns ON (ms.sentence_id = ns.sentence_id AND ns.project_id = 623483)
LEFT JOIN sentence_tokens nst ON (ms.sentence_id = nst.sentence_id AND nst.project_id = 623483)
WHERE ms.project_id = 623483

最佳答案

您应该能够使用连词来做到这一点:

SELECT rs.project_id,
ms.id AS raw_sentence_id,
rs.sentence AS raw_sentence_text,
rs.sentence_id AS raw_sentence_text_id,
rst.tokens AS tokenization_information,
ns.sentence_id AS normalized_sentence_id,
ns.sentence AS normalized_sentence_text,
nst.token_indices
FROM manual_sentences ms
JOIN sentences rs ON (ms.original_sentence_id = rs.sentence_id AND rs.project_id = 623483)
LEFT JOIN sentence_tokens rst ON (ms.original_sentence_id = rst.sentence_id AND ms.sentence_id = rst.sentence_id AND rst.project_id = 623483)
JOIN sentences ns ON (ms.sentence_id = ns.sentence_id AND ns.project_id = 623483)
WHERE ms.project_id = 623483

关于mysql - 我怎样才能合并连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47351410/

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