【问题标题】:Trouble with SQLite : Query Error: near FROM: syntax error Unable to execute statementSQLite 问题:查询错误:FROM 附近:语法错误无法执行语句
【发布时间】:2013-02-27 04:43:33
【问题描述】:

我在 SQLite 中不断收到此错误:

查询错误:“FROM”附近:语法错误无法执行语句

SELECT Name, CourseId
    FROM Lecturer JOIN Lecture ON Lecturer.LecturerId = Lecture.LecturerId
    JOIN     (SELECT CourseId   
        FROM Course
        WHERE EXISTS (SELECT * 
                    FROM Exam
                WHERE Exam.CourseId = Course.CourseId
                AND (SELECT COUNT *
                          FROM Exam
                          WHERE Grade > 6)
                <
                (SELECT COUNT *
                FROM Exam
                WHERE Grade < 6)))
    USING Course.Id     

【问题讨论】:

    标签: sqlite syntax


    【解决方案1】:

    COUNT 是一个函数,你需要在 * 周围加上括号

    如:

    COUNT(*)

    【讨论】:

      【解决方案2】:

      我通常会为内联视图分配一个别名,例如 FOO,并使用 on... 子句将外部表连接到内联视图:

        select * from x
        join
        (
            select someColumn, someOtherColumn...
      
        ) as FOO
        on x.somecolumn = FOO.somecolumn
      

      我会这样做:

        select lecture.*, FOO.courseid
        from lecture
        join lecturer on lecture.lecturerid = lecturer.lecturerid
        join
        (
             you inline view selecting the courses
      
        ) as FOO
        on lecture.courseid = FOO.courseid
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多