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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:40:21+00:00 2026-05-14T04:40:21+00:00

For the last few days I have been attempting to find a method to

  • 0

For the last few days I have been attempting to find a method to pull a very important set of information from a table that contains what I call daily counts. I have a table that is setup as follows.

person|company|prod1|prod2|prod3|gen_date

Each company has more than one person, and each person can have different combinations of products that they have purchased. What I have been trying to figure out is a SQL statement that will list the number of people that have bought a particular product per company. So an output similar to this:

Comp ABC | 13 Prod1 |  3 Prod2 | 5 Prod 3
Comp DEF |  2 Prod1 | 15 Prod2 | 0 Prod 3
Comp HIJ |  0 Prod1 |  0 Prod2 | 7 Prod 3 

Currently if a person did not select a product the value being stored is NULL.

Best I have right now is 3 different statements that can produce this information if run on their own.

SELECT Count(person) as puchases, company 
FROM Sales  WHERE prod1 = '1' and gendate = '3/24/2010' 
Group BY company
  • 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-14T04:40:21+00:00Added an answer on May 14, 2026 at 4:40 am
    SELECT      company,
                SUM(COALESCE(prod1, 0)) AS total_prod1,
                SUM(COALESCE(prod2, 0)) AS total_prod2,
                SUM(COALESCE(prod3, 0)) AS total_prod3
    FROM        Sales  
    WHERE       gendate = '2010-03-24' 
    GROUP BY    company
    

    But you definitely should normalize you table – split it in 4:

    • Company,
    • Person,
    • Product,
    • Person_Product_Purchase (with the date of the purchase).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very experienced in C/C++/Objective-C and over the last few days have been trying
Hi I have been learning WPF with Expression Blend 4 last few days and
Afternoon, I have been working with CKEditor and CKFinder for the last few days
I have been reading up and trying Git for the last few days and
OK I have been messing about with URL rewriting for the last few days
I have been searching through SO for the last few days and have found
I have been having this problem for the last few days and I can't
I have been coding up some map functionality. In the last few days, I
For the last few days, I have been trying to use Python for some
For the last few days I have been designing a layout for my website

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.