Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.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
基本SQL查询帮助_Sql_Postgresql - Fatal编程技术网

基本SQL查询帮助

基本SQL查询帮助,sql,postgresql,Sql,Postgresql,我为一个School项目创建了几个表。兴趣表是 //table courses CREATE TABLE courses(courseId SERIAL PRIMARY KEY, facultyId REFERENCES faculties(facultyId), courseName TEXT); //table weights CREATE TABLE weights(weightId SERIAL P

我为一个School项目创建了几个表。兴趣表是

                //table courses
        CREATE TABLE courses(courseId SERIAL PRIMARY KEY, facultyId REFERENCES faculties(facultyId), courseName TEXT);

                //table weights
    CREATE TABLE weights(weightId SERIAL PRIMARY KEY, weightName TEXT, weight INTEGER);

//table subjects
CREATE TABLE subjects(subjectId SERIAL PRIMARY KEY, subjectName TEXT);
        //table weights_subjects_courses
    CREATE TABLE weights_subjects_courses(courseId integer REFERENCES courses(courseId), weightId integer REFERENCES weights(weightId), subjectId integer REFERENCES subjects(subjectId)
当我尝试下面的查询时,问题出现了

SELECT * FROM courses, subjects, weights WHERE courses.courseId= weights_subjects_courses.courseId AND subjects.subjectId= weights_subjects_courses.subjectId AND weights.weightId= weights_subjects_courses.weightId ORDER BY courseName;
我得到这个错误 SQL错误:

ERROR:  missing FROM-clause entry for table "weights_subjects_courses"
LINE 1: ...ourses, subjects, weights WHERE courses.courseId= weights_su...
                                                             ^

提前感谢

您的where子句中有权重科目,但from子句中没有权重科目。无论何时在where子句中联接表,都需要将它们包括在from子句中


所以只需在from子句中添加权重、科目和课程,即可修复该错误

“无论何时在where子句中加入表,都需要将它们包括在from子句中。”谢谢:)任何时候,我想这只是一个疏忽;)