From: morphius on
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
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
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)*/