mariita
asked on
SQL query to find duplicate values using the HAVING clause
I'm trying to find duplicate values using the HAVING clause, but the SQL query below is returning the following error: "SQL command not properly ended". What am I doing wrong?
SELECT enrol.rep_start_year,
uni.university_code,
enrol.student_oen,
COUNT(*) AS duplicate_oen_count
FROM (SELECT rep_start_year, period,
student_oen,
fee_cat_type_id,
uni_institution_type_id,
reg_status_type_id
FROM edcs_unistat.ustat_enrolment_data) enrol
INNER JOIN edcs_unistat.uni_institution_type uniinst
ON enrol.uni_institution_type_id = uniinst.uni_institution_type_id
INNER JOIN
(SELECT u.university_id,
(CASE
WHEN u.university_code = 'DOMC' THEN 'CARL'
WHEN u.university_code = 'NOSM-LAKE' THEN 'NOSM'
WHEN u.university_code = 'NOSM-LAUR' THEN 'NOSM'
WHEN u.university_code = 'LAUR-ALGM' THEN 'ALGM'
WHEN u.university_code = 'LAUR-HRST' THEN 'HRST'
WHEN u.university_code = 'DOMC' THEN 'CARL'
ELSE u.university_code
END)
AS university_code
FROM edcs_core.university u) uni
ON uniinst.university_id = uni.university_id
INNER JOIN edcs_unistat.reg_status_type regstatus
ON enrol.reg_status_type_id = regstatus.reg_status_type_id
INNER JOIN edcs_unistat.fee_cat_type feetyp ON enrol.fee_cat_type_id = feetyp.fee_cat_type_id
where enrol.rep_start_year in ('2012', '2013')
AND regstatus.reg_status_type_code IN ('12','13','14','15','16','18')
AND feetyp.fee_cat_type_code IN ('3', '4')
and enrol.period in ('FAL')
GROUP BY enrol.rep_start_year, uni.university_code, enrol.student_oen
ORDER BY enrol.rep_start_year, uni.university_code, enrol.student_oen
HAVING COUNT(*) > 1
First thing I would do is get rid of the blank lines. Some tools don't like them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!