Using a SQL query, is it possible to count the number of Woocommerce orders for each user id?
SELECT customer_id FROM subscriptions
WHERE status = 'cancelled' GROUP BY customer_id
I’ve generated the list above of user id’s, now I need to find out how many orders each one has. How can I do that using an SQL query?
2
Answers
Have you tried with
count
:column_to_count
is the column you want to count(for example orders maybe…)Then you can use a
left join
Here is a small demo so you can show us if somethin is different.
You can use correlated sub-query :