Nancy Hardee-Cotton
Nancy Hardee-Cotton

Reputation: 1

Group By Error of SQL

Doing this query but keep getting error not in single-group or group function. Am new and learning what am I missing;

select distinct 
    spriden_id
  , spriden_last_name
  , spriden_first_name
  , saradap_term_code_entry
  , saradap_resd_code
  , saradap_admt_code
  , sarappd_apdc_code
  , sorlcur_levl_code
  , sorlcur_camp_code
  , sorlcur_program
  , goremal_email_address
  , goremal_preferred_ind
  , SUM(sfrstcr_credit_hr)
from spriden, saradap, sarappd, sorlcur, goremal, sfrstcr
where spriden_pidm = saradap_pidm
  and spriden_pidm = sorlcur_pidm
  and spriden_pidm = goremal_pidm
  and spriden_pidm = sarappd_pidm
  and spriden_pidm = sfrstcr_pidm
  and spriden_id like 'D%'
  and saradap_term_code_entry = '201701'
  and sorlcur_levl_code ='UG'
  and goremal_preferred_ind = 'Y'
  and sfrstcr_credit_hr < '1';

Upvotes: 0

Views: 97

Answers (2)

India.Rocket
India.Rocket

Reputation: 1235

I think sfrstcr_credit_hr is numeric that's why you are using < sign . So I have changed that also in my query

Try this and let me know whether it's working and you are getting the right results:-

select  
    spriden_id
  , spriden_last_name
  , spriden_first_name
  , saradap_term_code_entry
  , saradap_resd_code
  , saradap_admt_code
  , sarappd_apdc_code
  , sorlcur_levl_code
  , sorlcur_camp_code
  , sorlcur_program
  , goremal_email_address
  , goremal_preferred_ind
  , SUM(sfrstcr_credit_hr)
from spriden, saradap, sarappd, sorlcur, goremal, sfrstcr
where spriden_pidm = saradap_pidm
  and spriden_pidm = sorlcur_pidm
  and spriden_pidm = goremal_pidm
  and spriden_pidm = sarappd_pidm
  and spriden_pidm = sfrstcr_pidm
  and spriden_id like 'D%'
  and saradap_term_code_entry = '201701'
  and sorlcur_levl_code ='UG'
  and goremal_preferred_ind = 'Y'
  and sfrstcr_credit_hr < 1
  Group by     spriden_id
  , spriden_last_name
  , spriden_first_name
  , saradap_term_code_entry
  , saradap_resd_code
  , saradap_admt_code
  , sarappd_apdc_code
  , sorlcur_levl_code
  , sorlcur_camp_code
  , sorlcur_program

Upvotes: 0

alruizso
alruizso

Reputation: 11

Try:

select 
    spriden_id, spriden_last_name, spriden_first_name, saradap_term_code_entry, saradap_resd_code, saradap_admt_code, sarappd_apdc_code, sorlcur_levl_code, sorlcur_camp_code, sorlcur_program, goremal_email_address, goremal_preferred_ind, 
    SUM(sfrstcr_credit_hr) 
from 
    spriden, saradap, sarappd, sorlcur, goremal, sfrstcr 
where spriden_pidm = saradap_pidm 
    and spriden_pidm = sorlcur_pidm 
    and spriden_pidm = goremal_pidm 
    and spriden_pidm = sarappd_pidm 
    and spriden_pidm = sfrstcr_pidm 
    and spriden_id like 'D%' 
    and saradap_term_code_entry = '201701' 
    and sorlcur_levl_code ='UG' 
    and goremal_preferred_ind = 'Y' 
    and sfrstcr_credit_hr < '1'
group by spriden_id, spriden_last_name, spriden_first_name, saradap_term_code_entry, saradap_resd_code, saradap_admt_code, sarappd_apdc_code, sorlcur_levl_code, sorlcur_camp_code, sorlcur_program, goremal_email_address, goremal_preferred_ind;

Upvotes: 1

Related Questions