我正在尝试使用以下查询,但是它表示缺少运算符和语法错误。这个问题与ms访问有关。
select s.student_id, e.average_second_year_marks, e.average_third_year_marks, e.overall_marks
from students s
join
(
select student_id,
avg(case when program_year_when_enrolled = 'Second' then marks_obtained end)
as average_second_year_marks,
avg(case when program_year_when_enrolled = 'Third' then marks_obtained end)
as average_third_year_marks,
(
(sum(case when program_year_when_enrolled = 'Second' then marks_obtained end) * 1.0) +
(sum(case when program_year_when_enrolled = 'Third' then marks_obtained end) * 2.0)
) / 3.0 as overall_marks
from enrollment
group by student_id
) e on e.student_id = s.student_id
where s.course_current_status = 'Graduated-2017'
答案 0 :(得分:1)
等效的MS Access查询将更像这样:
select s.student_id, e.average_second_year_marks,
e.average_third_year_marks, e.overall_marks
from students as s inner join
(select student_id,
avg(iif(program_year_when_enrolled = "Second", marks_obtained, NULL)) as average_second_year_marks,
avg(iif(program_year_when_enrolled = "Third", marks_obtained, NULL)) as average_third_year_marks
(1.0 * avg(iif(program_year_when_enrolled = "Second", marks_obtained, NULL)) +
2.0 * avg(iif(program_year_when_enrolled = "Third", marks_obtained, NULL))
) / 3.0 as overall_marks
from enrollment
group by student_id
) as e
on e.student_id = s.student_id
where s.course_current_status = "Graduated-2017";