0

I have MySQL table 'orders' with following structure (removed some fields for this example for simplicity):

userid (user placed order)

payment_type (Can be A, B or C for example)

I need to make SQL query that will return me array of users counts for each payment method used for orders. So I will know something like this:

Payment method A - was used by 10 people

Payment method B - was used by 25 people

Payment method C - was used by 13 people

Note - I don't need to know orders counts with payment methods, I need to know how many unique users used every payment method.

I used this SQL but as I see it does not sum counts to show correct results and I don't know how to sum it correctly in SQL:

SELECT payment_type, count(*) AS value FROM orders GROUP BY user_id

Please help with correct SQL query.

Siva
  • 1,481
  • 1
  • 18
  • 29
Dmitry
  • 499
  • 1
  • 3
  • 19

1 Answers1

0

Thanks @PaulSpiegel , this is correct code for this:

SELECT payment_type, count(distinct user_id) AS value FROM orders GROUP BY payment_type
Dmitry
  • 499
  • 1
  • 3
  • 19