Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use "having sum" in a query

3312675Feb 21 2017 — edited Feb 21 2017

Hello All,

I need to change this portion (having sum(sfrstcr_credit_hr)>=12) of my script to give the following output -

having sum(sfrstcr_credit_hr)>=12 and >6

Basically, I need an output with credit less than 12 but more than 6. It doesn't work as above.

Here is the complete script.

select distinct

        sfrstcr_camp_code campus,

    spriden_id ID,

    substr(spriden_last_name,1,15) LNAME,

    substr(spriden_first_name,1,15) FNAME,

    sgbstdn_majr_code_1 MAJOR,

    stvmajr_desc DESCRIPTION,

    sum(sfrstcr_credit_hr) CREDITS

from

    saturn.spriden,

    saturn.sgbstdn,

    saturn.stvmajr,

    saturn.sfrstcr

where spriden_change_ind is null

    and sfrstcr_term_code = &term

    and spriden_pidm = sgbstdn_pidm

    and stvmajr_code = sgbstdn_program_1

    and sfrstcr_pidm = spriden_pidm

       and (sfrstcr_rsts_code like 'R%' or sfrstcr_rsts_code like 'K%')

       and sgbstdn_pidm = spriden_pidm

    and sfrstcr_levl_code in ('50')

       and sgbstdn_term_code_eff =

        (select max(b.sgbstdn_term_code_eff)

            from saturn.sgbstdn b

            where b.sgbstdn_pidm = spriden_pidm

            and b.sgbstdn_term_code_eff<= sfrstcr_term_code)

group by

    sfrstcr_camp_code,

        spriden_id,

    substr(spriden_last_name,1,15),

    substr(spriden_first_name,1,15),

    sgbstdn_majr_code_1,

    stvmajr_desc

having sum(sfrstcr_credit_hr)>=12

/

exit;

The red highlighted area is all I need changed.

Thanks

This post has been answered by John Thorton on Feb 21 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2017
Added on Feb 21 2017
5 comments
321 views