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

Can you help me to correct this query in sql

SELECT 
    STUDENT_NAME, SUBJECT, TYPE_OF_DISTRIBUTION, 
    SUM(POINTS) * WEIGHT_IN_PERCENTAGE / (COUNT(POINTS) * 100)
FROM 
    assignments a 
JOIN
    distributions d ON a.TYPE_OF_DISTRIBUTION = d.ASSIGNMENT_CATEGORY
GROUP BY
    SUBJECT, TYPE_OF_DISTRIBUTION, STUDENT_NAME 
ORDER BY
    STUDENT_NAME ASC;

ERROR at line 1:
ORA-00979: not a GROUP BY expression

>Solution :

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

You are getting this error for WEIGHT_IN_PERCENTAGE. If WEIGHT_IN_PERCENTAGE is same for every row in a group you can use (SUM(POINTS) * max(WEIGHT_IN_PERCENTAGE)) or you can SUM(POINTS*WEIGHT_IN_PERCENTAGE) multiply it with POINTS before sum:

SELECT 
    STUDENT_NAME, SUBJECT, TYPE_OF_DISTRIBUTION, 
    SUM(POINTS) * max(WEIGHT_IN_PERCENTAGE) / (COUNT(POINTS) * 100)
FROM 
    assignments a 
JOIN
    distributions d ON a.TYPE_OF_DISTRIBUTION = d.ASSIGNMENT_CATEGORY
GROUP BY
    SUBJECT, TYPE_OF_DISTRIBUTION, STUDENT_NAME 
ORDER BY
    STUDENT_NAME ASC;

OR

SELECT 
    STUDENT_NAME, SUBJECT, TYPE_OF_DISTRIBUTION, 
    SUM(POINTS * WEIGHT_IN_PERCENTAGE) / (COUNT(POINTS) * 100)
FROM 
    assignments a 
JOIN
    distributions d ON a.TYPE_OF_DISTRIBUTION = d.ASSIGNMENT_CATEGORY
GROUP BY
    SUBJECT, TYPE_OF_DISTRIBUTION, STUDENT_NAME 
ORDER BY
    STUDENT_NAME ASC;
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