Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 为什么“where”行会产生语法错误?_Mysql_Sql - Fatal编程技术网

Mysql 为什么“where”行会产生语法错误?

Mysql 为什么“where”行会产生语法错误?,mysql,sql,Mysql,Sql,我在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.

我在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”行[where lengtha.句子文本-lengthreplacea.句子文本,,+1>5]时,它运行得非常好。当我尝试使用它运行代码时,它会产生一个语法错误:

SQL 1064错误:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解第4行“inner joinselect b.transcription\u id,countb.transcription\u id as conta from”附近使用的正确语法

在查询中,WHERE子句应位于联接之后。以下查询将起作用:

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;

因为它在错误的地方

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;

语法错误,因为WHERE子句放错了位置如果答案有助于解决问题,您可能会