Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error while finding maximum number of students

I’m having these schema
STUDENT (Sid, Name, City, Adm_date, Paper1, Paper2)

And I want to find the maximum number of students were admitted in which date and the city where maximum number of students lives.

I’m using these queries in ORACLE 11g Express Edition:
For City:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT COUNT(Sid) AS No_of_students, City
FROM STUDENT
GROUP BY City
ORDER BY No_of_students DESC
LIMIT 1;

And For Date:

SELECT COUNT(Sid) AS No_of_students, Adm_date
           FROM STUDENT
           GROUP BY Adm_date
           ORDER BY No_of_students DESC
            LIMIT 1;

But here I’m getting error for both these tables:
ORA-00933: SQL command not properly ended

Here is my Table that I’m Using

>Solution :

Please try rownum with subquery (Since Limit is not available in Oracle):

For city wise:

select * from 
(SELECT COUNT(Sid) AS No_of_students, City
FROM STUDENT
GROUP BY City
ORDER BY No_of_students DESC) where rownum=1

For Adm_date wise:

select * from 
(SELECT COUNT(Sid) AS No_of_students, Adm_date
FROM STUDENT
GROUP BY Adm_date
ORDER BY No_of_students DESC) where rownum=1

Found a great article explaining the mechanism of selecting top-N rows using rownum:

https://blogs.oracle.com/oraclemagazine/post/on-rownum-and-limiting-results

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading