sql - Average of Sum minus Minimum -


hey guys, have sql statement grabs grades of different activity types (homework, quiz, etc), , if there's drop lowest type, drops, else, remains. errors below sql code.

select     student.firstname, student.lastname, 'grades' =            case                when grades.activitytype = 'homework'                 case when policy.drop_hw = 1                     (avg(sum(grades.grade) - min(grades.grade))) * (policy.homework / 100)                 else                     (avg(grades.grade) * (policy.homework / 100))                 end             end,  course.coursenum, course.sectnum, grades.activitytype  ... 

here errors i'm getting:

- cannot perform aggregate function on expression containing aggregate or subquery. - column 'policy.drop_hw' invalid in select list because not contained in either aggregate function or group clause.   

look analytical functions. (so question, oracle documentation).

something this:

avg(grades.grade) on (partition grades.student_id) avg_of_grades 

and:

(avg(sum(grades.grade) - min(grades.grade))) on (partition grades.student_id) avg_grades_with_drop 

set partitioning whatever makes sense in case; can't tell since omitted from ... in example.

you can use column aliases in calculations inside case statement.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -