Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:14:03+00:00 2026-06-01T21:14:03+00:00

The WordPress database structure looks like this: wp_users (ID, user_registered, etc) wp_usermeta (user_id, meta_key,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:14:04+00:00Added an answer on June 1, 2026 at 9:14 pm

    Give this a try:

    select sum(um.meta_value = '1') Sex1, sum(um.meta_value = '2') Sex2
    from wp_usermeta um
    join wp_users u on u.id = um.user_id
    where um.meta_key = 'sex'
    group by date(u.user_registered)
    

    You said:

    The result then should consist of two columns and as many rows as there are unique dates.

    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 the select statement to see that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the basic database structure for Users and UserRoles. My client wants to
I am grabbing posts from the WordPress database using this piece of code: $query
I created a code which generates content and I want to populate Wordpress's database
I have a site like SO, Wordpress, etc, where you make a post and
i have a question regarding the efficiency of word press database structure. My intended
wpdb class in wordpress is used for making connection to database. is there any
My wordpress sidebar widget disappeared when I changed the twitter link from the database
WordPress allows theme designers to place a 404.php file in their theme's directory. This
Wordpress has a filter that automatically add paragraphs to posts. I can remove this
I have an array with a series of event IDs organized like this: $event['year']['month']['day']

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.