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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:44:26+00:00 2026-05-17T23:44:26+00:00

I know just about the basic usage of COUNT(*) and I wonder if I

  • 0

I know just about the basic usage of COUNT(*) and I wonder if I can use it or some other function to get the following result.

I have a table with people and the products they have purchased (product_id_). I have second table which maps each product_code to a single product_category.

Using a simple SELECT I can combine both tables to get:

first last   product_code product_category
John  BGood  100          Food
John  BGood  29           Beverage
John  BGood  30           Beverage
Rita  Black  25           Fashion
Betty Rock   36           Electronics
Betty Rock   72           Food
Betty Rock   100          Food
Betty Rock   36           Electronics

But what I would like is to count for each person the number of products it purchased from each category. product_category is an enum with 5 possible values (the four above and Other). I would like to get a table like:

first last   product_category count
John  BGood  Food             1
John  BGood  Beverage         2
John  BGood  Fashion          0
John  BGood  Electronics      0
John  BGood  Other            0
Betty ...
  • 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-17T23:44:26+00:00Added an answer on May 17, 2026 at 11:44 pm
    SELECT first, last, product_category, COUNT(product_code)
    FROM <table>
    ORDER BY last, first
    GROUP BY first, last, product_category
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just curious to know about this.When i heard about Spring.net and tried some
I know about AJAX cross-domain policy. So I can't just call http://www.google.com over a
I am a systems programmer, so i just know some basic css/html. I like
I know basic stuff about UML: - Use Case - Activity Diagram - Class
I know this maybe a basic question but I just can't seem to find
I know I could just make all the Mix_Musics public, and not worry about
i just want to know about the files and folder structure for a site
i just want to know a general information about this particular information. Any good
Maybe I just don't know enough about structs and have been using them blindly
I am just learning and would like to know about a piece of code

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.