--- SQL 1
Select b.min as voteslow, b.max as voteshigh, count(totalvotes) as totalinrange from
(Select wins+losses as
totalvotes from pictures where status='A') a,
(
select 0 as min, 500 as max union
select 501 as min, 1000 as max union
select 1001 as min, 100000 as max union
select 0 as min, 100000 as max) b
where totalvotes >= b.min and totalvotes <=b.max
group by b.min, b.max
order by b.max, b.min desc
--- SQL 2
SELECT sum(total) as total, sum(zero_fifty) as p0_50, sum(fifty_onehund) as p50_100
FROM
(SELECT
SUM (CASE WHEN winpct >=0 and winpct <= 100 THEN 1 ELSE 0 END) as total,
SUM (CASE WHEN winpct >=0 and winpct <= 50 THEN 1 ELSE 0 END) as zero_fifty,
SUM (CASE WHEN winpct >=50 and winpct <= 100 THEN 1 ELSE 0 END) as fifty_onehund
FROM
(select wins, losses, wins+losses as total, (CONVERT(decimal(10, 5), wins) / (wins + losses)) * 100 as winpct
from pictures
where status='A' and wins+losses > 0 and wins+losses <= 100000) as winpcttable)
as raw_results
|