Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created September 18, 2019 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryhughes/300d6b06acdbdbcde43ff6988b7202b1 to your computer and use it in GitHub Desktop.
Save barryhughes/300d6b06acdbdbcde43ff6988b7202b1 to your computer and use it in GitHub Desktop.
Build a list of user IDs, ordered by the number of known (WooCommerce) subscriptions each user is associated with.
SELECT meta_value AS user_id,
COUNT(*) AS subscription_count
FROM wp_posts
JOIN wp_postmeta ON ID = post_id
WHERE post_type = 'shop_subscription'
AND meta_key = '_customer_user'
GROUP BY meta_value
ORDER BY subscription_count DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment