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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:24:55+00:00 2026-06-13T18:24:55+00:00

I have searched all the SQL questions and I have found every version of

  • 0

I have searched all the SQL questions and I have found every version of what I don’t want – so I need to ask. I am in a brain lock – knowing there is a count and sum and group and a join all thrown together.

2 Tables

  1. CustomerTable – CustID, CustQuality (values are good customer, bad customer, new customer etc)
  2. PurchaseTable (PurchID, PurchItem, PurchDate)

I am trying to count how many purchases by Good, Bad, New Customers in the last 30 days.

I have tried the join and group count etc and I keep getting:

  • GoodCustomer – CustID2 – 1 purch
  • GoodCustomer – CustID3 – 3 purch
  • GoodCustomer – CustID4 – 2 purch
  • BadCustomer – CustID7 – 2 purch
  • BadCustomer – CustID1 – 4 purch
  • NewCustomer – CustID9 – 1 purch
  • NewCustomer – CustID4 – 4 purch etc etc.

I just want the overall results

  • 3 Good Customers made 6 Purchases
  • 2 Bad Customers made 6 Purchases
  • 2 New Customers made 5 Purcahses

THEN FOR ADDITIONAL functioning… I have a 3rd table that I need to join as well. CustomerLocation (CLID, CLLocation (values of North, South, East, West))

So if I wanted to know the following break down of the groups

  • 3 Good Customers made 6 Purchases – 1 Customer was from the North, 2 Customers From South
  • 2 Bad Customers made 6 Purchases – 5 Customer from East, 1 West
  • 2 New Customers made 5 Purcahses – 2 Customer from South

And the last new query would be…
WHERE CLLocation = South

Or if I wanted to look up by region…

  • 1 Good Customers made 3 Purchases
  • 2 Bad Customers made 2 Purchases
  • 0 New Customers made 0 Purcahses

I KNOW I AM ASKING A LOT – BUT ANY AND ALL HELP WOULD BE GREATLY APPRECIATED!

  • 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-13T18:24:56+00:00Added an answer on June 13, 2026 at 6:24 pm
    SELECT C.CustQuality, COUNT(DISTINCT c.CustID) AS tot_Customer, COUNT(PurchID) AS tot_Purch
    FROM CustomerTable C, PurchaseTable P
    WHERE C.CustID = P.PurchCustID
    GROUP BY C.CustQuality;
    
    SELECT C.CustQuality, CL.CLocation,  COUNT(DISTINCT c.CustID) AS tot_Customer, COUNT(PurchID) AS tot_Purch
    FROM CustomerTable AS C, PurchaseTable AS P, CustomerLocation AS CL
    WHERE C.CustID = P.PurchCustID AND CL.LCTCustID = C.CustID
    GROUP BY C.CustQuality, CL.CLocation;
    
    SELECT C.CustQuality, CL.CLocation,  COUNT(DISTINCT c.CustID) AS tot_Customer, COUNT(PurchID) AS tot_Purch
    FROM CustomerTable AS C, PurchaseTable AS P, CustomerLocation AS CL
    WHERE C.CustID = P.PurchCustID AND CL.LCTCustID = C.CustID AND CL.CLocation='North'
    GROUP BY C.CustQuality;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all i want to say that i have searched each and every
I have searched online but all the answers I have found were very primitive.
OK I have looked and searched all i want to do is fire a
I've searched through all of the responses on SQL Developer and I haven't found
I have searched all morning and yesterday afternoon and still cannot find an solution
I have searched all over the web with no luck of making this project
So I have searched all over the place and I can not seem to
First of all I have searched many times in this forum but none is
I have read the documentation and searched all over but I can't find how
firstly i have searched a lot and all topics seems to be C# :

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.