Reputation: 826
I request your assistance in finding the count
and percent
of customers who had certain amount payments due. I am using SQL Server 2016.
select customer_id,payments from mytable
Customer_ID Payments
1 $50
2 $100
3 $500
4 $550
5 $500
6 $500
7 $500
8 $400
9 $550
10 $400
Results Requested:
Count Percent Payments
1 10% $50
2 20% $400
4 40% $500
2 20% $550
1 10% $100
Upvotes: 0
Views: 70
Reputation: 1269753
I think you want a window function:
select payment, count(*),
count(*) * 1.0 / sum(count(*)) over () as ratio
from t
group by payment;
Upvotes: 0