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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:21:29+00:00 2026-06-05T18:21:29+00:00

I have the following table that lists all awarded cups: Name: Cups Columns: Month,

  • 0

I have the following table that lists all awarded cups:


Name: Cups
Columns: Month, Cup, User

Example:
Month | Cup__ | User__
_____ | _____ | ______
Febru | Cup_1 | User_1
Febru | Cup_2 | User_1
March | Cup_1 | User_1
March | Cup_2 | User_2
April | Cup_2 | User_2

*There are only 2 different cups

I know how to get how much awards each user has (COUNT), even of a certain type (WHERE Cup=Cup_1), but how do i get all of that in the same query?

Example based on the table above:


User__ | Total | Cup_1 | Cup_2
______ | _____ | _____ | _____
User_1 | __3__ | __2__ | __1__
User_2 | __2__ | __0__ | __2__

User_1 has 3 cups, 2 of Cup_1 and 1 Cup_2.
User_2 has 2 cups, 2 of Cup_2.

Basically, the total column is the sum of the other columns.

  • 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-05T18:21:30+00:00Added an answer on June 5, 2026 at 6:21 pm

    It’s a little tedious, but it will look something like this

    SELECT User, COUNT(*) AS Total, SUM(IF(Cup = "Cup_1", 1, 0)) AS Cup_1, SUM(IF(Cup = "Cup_2", 1, 0)) AS Cup_2 FROM Cups GROUP BY User
    

    I’m using SUM with a conditional statement, to determine if the cup matches the value I’m looking for. It will add 1 if there’s a match, 0 if there isn’t. As previously noted, it’s a little tedious, but it will certainly work!

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

Sidebar

Related Questions

I have a following table using MVC that shows number of items the user
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a MEMBERS table with the following relevant columns: Name JoinDate Level --1=Gold,2=Silver,3=Bronze**
I have application with following design: Table View that lists documents. And ViewController where
I have the following table template that is rendered through knockout: <table class=gv data-bind=visible:
I have some data in a table that looks roughly like the following: table
The idea is that say you have the following table. ------------- | oID |
I have the following Table elements how do i run a query that reproduce
I have the following table, Persons_Companies , that shows a relation between persons and
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME

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.