how to use MAX function in case statement under sum expression in oracle sql? -


  select a.institution,          a.acad_career,          a.emplid,          a.strm,          nvl(              sum(                  case                      when     a.repeat_candidate in ('n', 'y')                           , a.crse_grade_off != 'f'                          max(grade_points)                      else                          (grade_points)                  end                 ),              0             )              gpa,          nvl(sum(case when a.repeat_candidate = 'n' a.unt_taken end), 0) taken,          a.acad_prog     ps_stdnt_enrl a, ps_stdnt_clas_d_vw b        a.emplid = b.emplid          , a.class_nbr = b.class_nbr          , a.strm = b.strm          , a.acad_career = b.acad_career          , a.stdnt_enrl_status = 'e'          , a.emplid '06381313011%' group a.emplid,          a.acad_career,          a.institution,          a.acad_prog,          a.strm 

this query work fine without max function bt here problems student can repeat passed course @ condition max value required return error not single group function.

you can't nest aggregation functions. try trick nested queries:

select   data.institution ,data.acad_career ,data.emplid ,data.strm ,nvl(sum(data.gpa), 0) gpa ,data.taken ,data.acad_prog    (select a.institution,          a.acad_career,          a.emplid,          a.strm,         max(grade_points) gpa,          nvl(sum(case when a.repeat_candidate = 'n' a.unt_taken end), 0) taken,          a.acad_prog     ps_stdnt_enrl a, ps_stdnt_clas_d_vw b        a.emplid = b.emplid          , a.class_nbr = b.class_nbr          , a.strm = b.strm          , a.acad_career = b.acad_career          , a.stdnt_enrl_status = 'e'          , a.emplid '06381313011%' group a.emplid,          a.acad_career,          a.institution,          a.acad_prog,          a.strm ) data group    data.institution ,data.acad_career ,data.emplid ,data.strm ,data.taken ,data.acad_prog 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -