| Author |
Topic |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2011-11-17 : 17:20:42
|
| will like to get the percentage for the testgroups and group by purchasesiteidresult:10%15%25%50%10%40%50%declare @t1 table (counts int, purchasesiteid int, testgroup varchar(50))insert @t1select 100, 1024, NULL union allselect 50, 1024, 'Control' union allselect 20, 1024, 'Production' union allselect 30, 1024, 'Beta' union allselect 40, 2048, 'Production' union allselect 10, 2048, 'Beta' union allselect 50, 2048, NULL select 100*counts/(select sum(counts) from @t1) as percentage, purchasesiteid, testgroup, counts from @t1group by purchasesiteid, counts, testgrouporder by purchasesiteid |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2011-11-18 : 18:22:45
|
| thanks |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2011-11-22 : 12:26:23
|
| Is there a way to do it without using OVER PARTITION? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-22 : 12:36:17
|
quote: Originally posted by basicconfiguration Is there a way to do it without using OVER PARTITION?
whay whats the issue in using it?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2011-11-22 : 14:26:54
|
| No issues. I just want to know how to do it the othr way. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-11-22 : 14:56:54
|
Here are some other less elegant ways :)SELECT T1.testgroup, T1.purchasesiteid, T1.counts, 100.00/(T.SumCounts /cast(T1.counts as real))FROM @t1 AS T1INNER JOIN ( SELECT purchasesiteid, SUM(counts) AS SumCounts FROM @t1 GROUP BY purchasesiteid ) AS T ON T1.purchasesiteid = T.purchasesiteidSELECT T1.testgroup, T1.purchasesiteid, T1.counts, 100.00/(T.SumCounts /cast(T1.counts as real))FROM @t1 AS T1OUTER APPLY ( SELECT purchasesiteid, SUM(counts) AS SumCounts FROM @t1 WHERE purchasesiteid = T1.purchasesiteid GROUP BY purchasesiteid ) AS T |
 |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2011-11-25 : 18:16:06
|
| thanks lamprey |
 |
|
|
|