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

  • SEARCH
  • Home
  • 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 1083565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:27:06+00:00 2026-05-16T22:27:06+00:00

I have 2 tables: members, orders. Members: MemberID, DateCreated Orders: OrderID, DateCreated, MemberID I

  • 0

I have 2 tables: members, orders.

Members: MemberID, DateCreated
Orders:  OrderID, DateCreated, MemberID

I want to find out the number of new members in a given month broken down into number of order groups, eg. 5+, 4, 3, 2, 1, 0

I’ve got the query to work out the number of orders for a member but how can I get these values in one query?

SELECT
  COUNT(o.orderid) AS Purchases
FROM
  members m
  LEFT JOIN orders o ON o.memberid = m.memberid
    AND MONTH(o.DateCreated) = 8
WHERE
  MONTH(m.DateCreated) = 8
GROUP BY
  m.memberid
ORDER BY
  COUNT(o.orderid) DESC
  • 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-05-16T22:27:07+00:00Added an answer on May 16, 2026 at 10:27 pm

    There’s a couple ways you can do this, some of which could be fairly complicated.

    This is the way I would do, focusing on the new member part rather than the count part:

      SELECT COUNT(M.MemberID),
             (SELECT COUNT(*) FROM Orders O WHERE O.MemberId = M.MemberId AND O.DateCreated BETWEEN '2010-08-01' AND DATE_ADD('2010-08-01', INTERVAL 1 MONTH)) AS num_orders
        FROM Members M
       WHERE M.DateCreated BETWEEN '2010-08-01' AND DATE_ADD('2010-08-01', INTERVAL 1 MONTH)
    GROUP BY num_orders
    

    I did the lookup with dates because it would be faster (it could make use of an index whereas MONTH(M.DateCreated) would always do a full table scan, but you can change it back if really do need all orders/members from a given month).

    EDIT:
    I forgot to handle the 5+ part of the question so here’s an option for that:

      SELECT COUNT(M.MemberID),
             (SELECT IF(COUNT(*) >= 5, '5+', COUNT(*)) FROM Orders O WHERE O.MemberId = M.MemberId AND O.DateCreated BETWEEN '2010-08-01' AND DATE_ADD('2010-08-01', INTERVAL 1 MONTH)) AS num_orders
        FROM Members M
       WHERE M.DateCreated BETWEEN '2010-08-01' AND DATE_ADD('2010-08-01', INTERVAL 1 MONTH)
    GROUP BY num_orders
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that I have 2 tables : members and orders (Mysql) Members : id
I have five tables in my database. Members, items, comments, votes and countries. I
The case: I have 2 tables, 'contracts' and 'members' tied with contract.id = members.cid.
I have 3 tables: Member, Employer, and Location. Member has MemberID, EmployerID, and LocationID.
Using T-SQL I have 2 tables one which lists all members(recEntrants). The second table(recEntrantStatus)
I have F.FRIENDID, F.MEMBERID columns in FRIENDS table and M.MEMBERID, M.FIRSTNAME, M.LASTNAME in MEMBERS
I am trying to find out what is causing this error, I have listed
I have the following tables: platforms(id,platformname) games(id,title,platformid) gameslists(id,memberid,gameid) I would like to select all
I have three tables as follows and am trying to extract the number of
I have following mysql tables. 1. members ---------- |id |name| ---------- |001|aaa | |002|bbb

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.