我有两个表,课程和学院。
Courses 中的instructor_id 引用Faculties 中的faculty_id。
我正在尝试编写一个查询,其中列出了教授多门课程的所有教师。由于我是 SQL 的新手,所以我完全不知道如何去做。Courses 表中存在与instructor_id 值相同的行。到目前为止,我已经加入了这样的表格:
SELECT "Courses".description, "Faculties".name FROM "Courses" INNER JOIN
"Faculties" ON "Courses".instructor = "Faculties".faculty_id;
Run Code Online (Sandbox Code Playgroud)
但我不知道如何过滤掉在 Instructor 列下重复值的行(换句话说,过滤具有相同讲师的班级)。
我有这个功能。它还不完整,也没有做任何有意义的事情,但在编写过程中我遇到了这个错误:
ERROR: syntax error at or near "LOOP"
LINE 26: END LOOP;
Run Code Online (Sandbox Code Playgroud)
有人可以看看我的代码并明白为什么吗?我的 for 循环语法对我来说看起来很好。
CREATE FUNCTION assignGrades(prob numeric[], school_name text, school_id bigint) RETURNS void AS $$
DECLARE
num_grades integer ARRAY[6];
found_school school_probs%ROWTYPE;
num_students simulated_records%ROWTYPE;
num_students_int bigint;
random_record simulated_records%ROWTYPE;
BEGIN
SELECT INTO found_school * FROM school_probs WHERE school_code = school_id;--select the prob dist
SELECT INTO num_students * FROM simulated_records WHERE school = school_name;
SELECT COUNT(*) INTO num_students_int FROM simulated_records WHERE school = school_name;
num_grades[1] = num_students_int*found_school.probs[1];
num_grades[2] = num_students_int*found_school.probs[1];
num_grades[3] …Run Code Online (Sandbox Code Playgroud)