Reputation: 484
This table is updated whenever a customer buys anything:
I want to find out a query to know the frequency distribution of number of customers and number of items bought. For example the number of customers who have bought 1 item, 2 items and so on.
Upvotes: 1
Views: 4120
Reputation: 434755
Something like this should do the trick:
select items_bought, count(*) as customers
from (
select customerid, count(*) as items_bought
from your_table
group by customerid
) dt
group by items_bought
First you group by customerid
to get your counts and then group by the counts to get your histogram values. This will give you the number of items bought in items_bought
and the number of customers that bought that many in customers
.
Upvotes: 9