选择带有join -syntax错误的查询

时间:2017-09-29 15:53:53

标签: mysql sql

SELECT SampleSheet.Id,SampleSheet.Sample_Complete,SampleSheet.SampleName,"
                + "count(Job.sampleId) AS NumberOfSamples FROM (SampleSheet "
                + "LEFT JOIN Job ON SampleSheet.Id = Job.sampleId) "
                + "WHERE SampleSheet.Sample_Complete=?"
                + "GROUP BY SampleSheet.Id

请问任何人请告诉我这个查询中有什么不对。我收到语法错误。

如果我不使用Where条件,它的工作正常。但我需要获取样本完成的行。

SELECT SampleSheet.Id,SampleSheet.Sample_Complete,SampleSheet.SampleName,count(Job.sampleId) AS NumberOfSamples FROM (SampleSheet LEFT JOIN Job ON SampleSheet.Id = Job.sampleId) GROUP BY SampleSheet.Id

1 个答案:

答案 0 :(得分:3)

有几点建议。在WHERE子句

之后似乎是空间问题
            + "WHERE SampleSheet.Sample_Complete=?"
            + "GROUP BY SampleSheet.Id

代替

            + "WHERE SampleSheet.Sample_Complete=? "
            + "GROUP BY SampleSheet.Id

您也可以在(之后删除FROM,并明显)。这不是必需的。

 FROM (SampleSheet "
            + "LEFT JOIN Job ON SampleSheet.Id = Job.sampleId) "