我有一个POSTGRESQL更新语句,我尝试使用显式连接重写并需要一些帮助,以便识别NESTED select语句别名来执行外部UPDATE语句。不确定为什么" se"无法识别嵌套选择的别名。我知道我必须遗漏一些基本的东西。
任何帮助/指示将不胜感激。感谢。
错误我得到了:
ERROR: schema "se" does not exist
********** Error **********
ERROR: schema "se" does not exist
SQL state: 3F000
这是我的代码:
UPDATE students
SET custom_400011449 = CAST(cfso1.label as integer)+1,
custom_400011770 = 761 --'2016-2017'
FROM (
SELECT se2.student_id, cfso1.id, cfso1.label
FROM students s
INNER JOIN student_enrollment se2
ON s.student_id = se2.student_id
INNER JOIN school_gradelevels sg
ON se2.grade_id = sg.id
INNER JOIN custom_field_log_entries sle
ON se2.student_id = sle.source_id
LEFT JOIN custom_field_select_options cfso1
ON s.custom_400011449 = cfso1.id
LEFT JOIN custom_field_select_options cfso2
ON s.custom_400011770 = cfso2.id
LEFT JOIN custom_field_select_options cfso3
ON sle.log_field4::INT = cfso3.id
WHERE se2.syear =2016
AND s.custom_400011449 IS NOT NULL
AND s.custom_400011898 IS NULL
AND s.custom_400011899 IS NULL
AND sle.field_id = 15 --400010549
AND sle.log_field2 IS NULL
AND cfso2.label = '2015-2016'
AND cfso3.label IN ('LE', 'NL-F', 'NL-S')
AND sg.short_name BETWEEN '01' AND '12'
AND (
SELECT COUNT(school_date)
FROM student_enrollment se
INNER JOIN attendance_calendar ac
ON se.calendar_id = ac.calendar_id
WHERE se.student_id = se2.student_id
AND se.syear =2016 --{SYEAR}
AND ac.syear =2016 --{SYEAR}
AND ac.school_date >= se.start_date
AND ac.school_date <= NOW()
AND (se.end_date IS NULL OR ac.school_date <= se.end_date)
AND se.custom_9 IS NULL
AND se2.start_date >= '2016-08-22'
GROUP BY se.student_id
HAVING COUNT(ac.school_date) >= 59)
>= 59) AS se
LEFT JOIN custom_field_select_options cfso1
ON se.cfso1.id = cfso1.id
WHERE students.student_id = se.student_id
答案 0 :(得分:0)
我发现我的问题是在ON条件“se.cfso1.id”中出现语法错误。一旦我解决了问题就解决了。