Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help in Query

Author  Topic 

geniussandy
Starting Member

1 Post

Posted - 2010-09-01 : 12:10:18
I have 3 tables
login ( student_id,password)
student_academics_info(student_id,CGPA,branch)

where CGPA is Cumulative Grade Point Average at scale of 10

student_personal_info(student_id,sex)


i want to write a query to get average CGPA of males of each branch and average CGPA of females of each branch.



--
Sandeep Agarwal

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-01 : 12:12:50
whats formula?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rohitvishwakarma
Posting Yak Master

232 Posts

Posted - 2010-09-02 : 08:35:54
hi sandeep,

Following is the query:

SELECT A.branch,P.student_sex,SUM(A.CGPA) as TotalCGPA, COUNT(L.student_id) TotalStudents ,SUM(A.CGPA)/COUNT(L.student_id) AS Average
FROM login L
INNER JOIN student_academics_info A
ON L.student_id = A.student_id
INNER JOIN student_personal_info P
ON L.student_id =P.student_id
WHERE branch IN (select distinct branch from student_academics_info )
GROUP BY A.branch,P.student_sex

If there is any issue with the query or you need more details then feel free to revert back
Go to Top of Page
   

- Advertisement -