From: morphius on 28 Jan 2010 08:26 tblid name ordered_bit 1 A 1 2 A 0 3 A 1 4 A 0 desired result: name ordered_bit A 50 /*50 is the percentage (2/4)*/
From: Tom Moreau on 28 Jan 2010 08:50 Try: select [name] , sum (cast (ordered_bit as float)) / cast (count (*) as float) * 100.0 as ordered_bit from MyTable group by [name] -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS SQL Server MVP Toronto, ON Canada https://mvp.support.microsoft.com/profile/Tom.Moreau "morphius" <morphius(a)discussions.microsoft.com> wrote in message news:A6138986-9BA8-43DA-8F25-B61AE2A07436(a)microsoft.com... tblid name ordered_bit 1 A 1 2 A 0 3 A 1 4 A 0 desired result: name ordered_bit A 50 /*50 is the percentage (2/4)*/
From: Uri Dimant on 28 Jan 2010 09:07 CREATE TABLE #tmp( tblid INT , name CHAR(1), ordered_bit TINYINT ) INSERT INTO #tmp VALUES (1,'A',1) INSERT INTO #tmp VALUES (2,'A',0) INSERT INTO #tmp VALUES (3,'A',1) INSERT INTO #tmp VALUES (4,'A',0) SELECT 100.0*COUNT (CASE WHEN ordered_bit=1 THEN 1 END)/MAX(tblid) FROM #tmp "morphius" <morphius(a)discussions.microsoft.com> wrote in message news:A6138986-9BA8-43DA-8F25-B61AE2A07436(a)microsoft.com... > tblid name ordered_bit > 1 A 1 > 2 A 0 > 3 A 1 > 4 A 0 > > desired result: > name ordered_bit > A 50 > > /*50 is the percentage (2/4)*/
|
Pages: 1 Prev: Upgrade MS SQL 2000 Cluster to SP4 Next: Can't Restore Database to New Server |