Почему строка 'where' вызывает синтаксическую ошибку? - PullRequest
0 голосов
/ 03 июля 2019

У меня есть следующие консультации в MySQL:

select a.transcription_id, a.speaker, a.sentence_text, a.tokenize_sentences
from sentences_type as a
where (length(a.sentence_text) - length(replace(a.sentence_text, ' ', '')) + 1) > 5
inner join(
select b.transcription_id, count(b.transcription_id) as conta
from sentences_type as b
group by transcription_id
having conta = 2) as c
on a.transcription_id = c.transcription_id;

Когда я снимаю строку 'where' [где (length (a.sentence_text) - длина (replace (a.sentence_text, '','')) + 1)> 5], работает отлично.Когда я пытаюсь запустить код с ним, он выдает синтаксическую ошибку:

Ошибка SQL (1064): в синтаксисе SQL есть ошибка;проверьте руководство, соответствующее вашей версии сервера MySQL, чтобы найти правильный синтаксис для использования рядом с 'внутренним соединением (выберите b.transcription_id, count (b.transcription_id) как контакт из' в строке 4

Ответы [ 2 ]

1 голос
/ 03 июля 2019

В вашем запросе предложение WHERE должно быть после JOIN. Будет работать следующий запрос:

SELECT a.transcription_id,
       a.speaker,
       a.sentence_text,
       a.tokenize_sentences
FROM sentences_type AS a
INNER JOIN (
    SELECT b.transcription_id,
           COUNT(b.transcription_id) AS conta
    FROM sentences_type AS b
    GROUP BY transcription_id
    HAVING conta = 2
    ) AS c
    ON a.transcription_id = c.transcription_id
WHERE (LENGTH(a.sentence_text) - LENGTH(REPLACE(a.sentence_text, ' ', '')) + 1) > 5;
0 голосов
/ 03 июля 2019

Потому что это не в том месте

select a.transcription_id, a.speaker, a.sentence_text, a.tokenize_sentences
from sentences_type as a
inner join(
    select b.transcription_id, count(b.transcription_id) as conta
    from sentences_type as b
    group by transcription_id
    having conta = 2) as c on a.transcription_id = c.transcription_id
where (length(a.sentence_text) - length(replace(a.sentence_text, ' ', '')) + 1) > 5;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...