The WordPress database structure looks like this:
- wp_users (ID, user_registered, etc)
- wp_usermeta (user_id, meta_key, meta_value, etc)
wp_users.ID corresponds to wp_usermeta.user_id.
I want to to select the count of all users grouped by DATE(wp_users.user_registered) and by their meta value corresponding to meta key 'sex' which is either 1 or 2. The result then should consist of two columns and as many rows as there are unique dates. The first column should be the count of the number of users having meta value 1 and the second column the count of the number of users having meta value 2.
I’m not interested in WP specific constructs, I want to do this with one single SQL query.
I would post my attempt if it was good enough, unfortunately I don’t have one that good. Really would appreciate any help.
Give this a try:
You said:
The problem with this is that you won’t know what date are each row is referring to. You could add
date(u.user_registered)to theselectstatement to see that.