結果太多,我想雙方都知道下面的查詢,從查詢
SELECT s.LAST_NAME||', '||s.FIRST_NAME||' '||COALESCE(s.MIDDLE_NAME,' ') AS FULL_NAME,
s.LAST_NAME,
s.FIRST_NAME,
s.MIDDLE_NAME,
s.STUDENT_ID,
ssm.SCHOOL_ID,
ssm.SCHOOL_ID AS LIST_SCHOOL_ID,
ssm.GRADE_ID ,
sg1.BENCHMARK_ID,
sg1.GRADE_TITLE,
sg1.COMMENT AS COMMENT_TITLE,
ssm.STUDENT_ID,
sg1.MARKING_PERIOD_ID,
sg1.LONGER_COURSE_COMMENTS,
sp.SORT_ORDER,
sched.COURSE_PERIOD_ID
FROM STUDENTS s,
STUDENT_ENROLLMENT ssm ,
SCHEDULE sched
LEFT OUTER JOIN STUDENT_REPORT_CARD_BENCHMARKS sg1 ON (
sg1.STUDENT_ID=sched.STUDENT_ID
AND sched.COURSE_PERIOD_ID=sg1.COURSE_PERIOD_ID
AND sg1.MARKING_PERIOD_ID IN ('0','442','445','450')
AND sg1.SYEAR=sched.SYEAR)
LEFT OUTER JOIN COURSE_PERIODS rc_cp ON (
rc_cp.COURSE_PERIOD_ID=sg1.COURSE_PERIOD_ID
AND rc_cp.DOES_GRADES='Y')
LEFT OUTER JOIN SCHOOL_PERIODS sp ON (sp.PERIOD_ID=rc_cp.PERIOD_ID)
WHERE ssm.STUDENT_ID=s.STUDENT_ID
AND ssm.SCHOOL_ID='1'
AND ssm.SYEAR='2010'
AND ('22-APR-11' BETWEEN ssm.START_DATE AND ssm.END_DATE OR (ssm.END_DATE IS NULL))
AND (LOWER(s.LAST_NAME) LIKE 'la''porsha%' OR LOWER(s.FIRST_NAME) LIKE 'la''porsha%')
AND sched.STUDENT_ID=ssm.STUDENT_ID AND sched.MARKING_PERIOD_ID IN ('0','444','446','447','445','448','450','443','449')
AND ('22-APR-11' BETWEEN sched.START_DATE AND sched.END_DATE OR (sched.END_DATE IS NULL AND '22-APR-11'>=sched.START_DATE))
ORDER BY s.LAST_NAME,s.FIRST_NAME
並修改它返回正確的結果 - 只返回一個不同的人。當搜索到任何特定人員時,會返回多個結果,因爲從schedule.course_period_id
返回了唯一值。由於在course_period_id
字段上有幾個左外部連接,但跨越不同的表,所以我很困惑在哪裏修改查詢。
好主人,至少嘗試並格式化代碼。沒有人有任何理解目前狀況正在發生的事情。 – YXD 2011-04-25 17:43:20
這是一個非常混亂的查詢 – Lamak 2011-04-25 17:44:32
我會解決的第一件事是在相同的查詢中使用隱式和顯式連接。這可能會導致錯誤,不應該完成。事實上,沒有任何藉口使用隱含的語法。 – HLGEM 2011-04-25 17:55:29