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.
| Author |
Topic |
|
sachin.hingole
Starting Member
15 Posts |
Posted - 2008-12-23 : 02:13:19
|
| Hi everybody I have to find out the % of races from the table my table has the records as followsI am joining organiztion table with its employee then with racesand finding count by grouping the racesits giving me below tableOrganizationName | Races | CountTest1 |African American | 2Test1 |American Indian | 4Test1 |Asian | 3Test2 |American | 6Test2 |American Indian | 23Test2 |Asian | 5so I need % of "African American" and % of "American Indian" and % of "Asian" from org Test1 same for Test2 organizationand here Races are of type 6 as follows1. White2. African American3. Hispanic4. Asian5. American Indian6. OtherThanks in advanceSachin Hingole |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2008-12-23 : 04:30:31
|
| SELECT t.OrganizationName,t.Races,r.percentage FROM yourtable tCROSS APPLY(SELECT t.count/CONVERT(DECIMAL(18,2),SUM(count)) AS 'percentage' FROM yourtable WHERE OrganizationName = t.OrganizationName) rJai Krishna |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-23 : 05:26:16
|
| SELECT e.test,t1.count/CONVERT(DECIMAL(18,2),SUM(e.count)) AS 'percentage' FROM ex einner join ex AS t1 on t1.test = e.test group by e.test,t1.count |
 |
|
|
|
|
|