Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

Here i want to Find Ratios in sqlquery.In my Project i want to Implement Ratios of Students and staff in Perticular District

So iam sucess up to this:
My OutPut:

txtDistName      intStaff   intStudents
Zanzibar Urban   212130     168



So now i wat to Display the ratio of intsatff and intStudents
txtDistName      intStaffStudents
Zanzibar Urban   212130/100:168/100


So i want the rations of that Coloumns

Iam Sending my sample Query:


SQL
SELECT        ntblDistrict_1.txtDistrictName, SUM(tblSummaryStudents.intMale + tblSummaryStudents.intFemale) AS intStudents, 
                         SUM(tblSummaryOthers.intTeachersMale + tblSummaryOthers.intTeachersFemale) AS intStaff
FROM            ntblDistrict AS ntblDistrict_1 INNER JOIN
                         ntblPrimarySchoolList ON ntblDistrict_1.intDistrictID = ntblPrimarySchoolList.intDistrictID INNER JOIN
                         tblSchool ON ntblPrimarySchoolList.intPrimaryListID = tblSchool.intPrimaryListID INNER JOIN
                         tblSummaryOthers ON tblSchool.intSchoolID = tblSummaryOthers.intSchoolID INNER JOIN
                         tblSummaryStudents ON tblSchool.intSchoolID = tblSummaryStudents.intSchoolID
WHERE        (ntblDistrict_1.intDistrictID IN
                             (SELECT        intDistrictID
                               FROM            ntblDistrict AS ntblDistrict
                               WHERE        (intDistrictID = 9)))
GROUP BY ntblDistrict_1.txtDistrictName



Regards,

Anilkumar.D
Posted
Updated 15-Nov-11 22:16pm
v2
Comments
Mehdi Gholam 16-Nov-11 4:16am    
EDIT -> fixed formatting

1 solution

select txtDistName, cast(intStaff/intStaff+intStudents) as decimal(20,2) as StaffRatio, cast(intStudents/intStaff+intStudents) as decimal(20,2) as StudentRatio from ...
 
Share this answer
 
Comments
Anil Honey 206 16-Nov-11 4:33am    
where should i put the solution in my query
deepakdynamite 17-Nov-11 1:33am    
Fire my query on your query. Inshort use your query as result and write my query on it.

Like "Select t.abc from (Select .... from ... ) as t"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900