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!

SQL query Group by on multiple tables

HKumar679Mar 27 2017 — edited Mar 28 2017

My Tables :-

Groups:

GID,Gname,category,DeptID

Departments:

DeptID,GID,duration,SID,Year

Trying to fetch  the below.. but its returning duplicate count in no of slots and duration.I am looking to fetch all departments ID's with sum of duration & count of slots for each dept ID's in a single query.

Please correct my query.

Thank you in advance.

SELECT Departments.GID,Departments.DeptID,Groups.Gname,Groups.category,

SUM(Departments.DURATION) as Total_Duration,count(Departments.SID) as Total_No_OF_Slots,Departments.Year

FROM Groups,Departments 

WHERE Groups.GID=Departments.GID  AND Groups.DeptID=Departments.DeptID AND Departments.Year='LIVE-16-17'

GROUP BY Departments.GID,Departments.DeptID,Groups.Gname,Groups.category,Departments.Year

ORDER BY Departments.GID;

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2017
Added on Mar 27 2017
11 comments
2,713 views