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 5989531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:06:53+00:00 2026-05-22T23:06:53+00:00

I am having trouble developing some queries on the fly for our clients and

  • 0

I am having trouble developing some queries on the fly for our clients and sometimes find myself asking “Would it be better to start with a subset of the data I know I’m looking for, then just import into a program like Excel and process the data accordingly using similar functions, such as Pivot Tables”?.

One instance in particular I am struggling with is the following example:

I have an online member enrollment system. For simplicity sake, let’s assume the data captured is: Member ID, Sign Up Date, their referral code, their state.

A sample member table may look like the following:

MemberID  | Date   | Ref    | USState
=====================================
1         | 2011-01-01  | abc   | AL
2         | 2011-01-02  | bcd   | AR
3         | 2011-01-03  | cde   | CA
4         | 2011-02-01  | abc   | TX

and so on….

ultimately, the types of queries I want to build and run with this data set can extend to:
“Show me a list of all referral codes and the number of sign ups they had by each month in a single result set”.

For example:

Ref   | 2011-01 | 2011-02 | 2011-03 | 2011-04
==============================================
abc   |   1     |   1     |   0     |  0
bcd   |   1     |   0     |   0     |  0
cde   |   1     |   0     |   0     |  0

I have no idea how to build this type of query in MySQL to be honest (I imagine if it can be done it would require a LOT of code, joins, subqueries, and unions.

Similarly, another sample query may be how many members signed up in each state by month

USState  | 2011-01 | 2011-02 | 2011-03 | 2011-04
==============================================
AL  |   1     |   0     |   0     |  0
AR  |   1     |   0     |   0     |  0
CA  |   1     |   0     |   0     |  0
TX  |   0     |   1     |   0     |  0

I suppose my question is two fold:

1) Is it in fact best to just try and build these out with the necessary data from within a MySQL GUI such as Navicat or just import the entire subset of data into Excel and work forward?

2) If I was to use the MySQL route, what is the proper way to build the subsets of data in the examples mentioned below (note that the queries could become far more complex such as “Show how many sign ups came in for each particular month by each state and grouped by each agent as well (each agent has 50 possible rows)”

Thank you so much for your assistance ahead of time.

  • 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-22T23:06:54+00:00Added an answer on May 22, 2026 at 11:06 pm

    I am a proponent of doing this kind of querying on the server side, at least to get just the data you need.

    You should create a time-periods table. It can get as complex as you desire, going down to days even.

    id   year    month  monthstart  monthend
    1    2011    1      1/1/2011    1/31/2011
    ...
    

    This gives you almost limitless ability to group and query data in all sorts of interesting ways.

    Getting the data for the original referral counts by month query you mentioned would be quite simple…

    select a.Ref, b.year, b.month, count(*) as referralcount
    from myTable a
    join months b on a.Date between b.monthstart and b.monthend
    group by a.Ref, b.year, b.month
    order by a.Ref, b.year, b.month
    

    The result set would be in rows like ref = abc, year = 2011, month = 1, referralcount = 1 as opposed to a column for every month. I am assuming that since getting a larger set of data and manipulating it in Excel was an option, that changing the layout of this data wouldn’t be difficult.

    Check out this previous answer that goes into a little more detail about the concept with different examples: SQL query for Figuring counts by month

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

Sidebar

Related Questions

Hey guys, I'm having some trouble with a screen from the app I'm developing.
I've been looking into developing applications for iOS using Flash CS5.5, however I'm having
in developing a more complicated script I am having a rather odd problem with
I am having trouble sending data on a socket from an iphone application I
Having trouble with a query to return the newest order of any grouped set
Having trouble with the db.alter command when changing a date field from null=True and
Im having trouble with sessions in IE. I have tested in IE 7-8, but
I am currently developing an application using the Flashbuilder 4.5 framework and I am
I am developing a SIP controller in Java using the NIST implementation of the

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.