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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:50:56+00:00 2026-06-10T13:50:56+00:00

I have the following table: scores: user_id | match_id | points 1 | 110

  • 0

I have the following table:

scores:

user_id | match_id | points
   1    |   110    |   4
   1    |   111    |   3
   1    |   112    |   3
   2    |   111    |   2

Users bet on matches and depending on the result of the match they are awarded with points. Depending on how accurate the bet was you are either awarded with 0, 2, 3 or 4 points for a match.

Now I want to rank the users so that i can see who is in 1st, 2nd place etc…
The ranking order is firstly by total_points. If these are equal its ordered by the amount of times a user has scored 4 points then by the amount of times a user scored 3 points and so on.

For that i would need the following table:

user_id |  total_points | #_of_fours | #_of_threes | #_of_twos
   1    |       10      |      1     |       2     |     0
   2    |        2      |      0     |       0     |     1

But i cant figure out the join statements which would help me get it.

This is as far as i get without help:

SELECT user_id, COUNT( points ) AS #_of_fours FROM scores WHERE points = 4 GROUP BY user_id

Which results in

user_id | #_of_fours
    1   |      1
    2   |      0

Now i would have to do that for #_of_threes and twos aswell as total points and join it all together, but i cant figure out how.

BTW im using MySQL.

Any help would be really apreciated. Thanks in advance

  • 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-10T13:50:57+00:00Added an answer on June 10, 2026 at 1:50 pm

    Using mysql syntax, you can use SUM to count the matching rows easily;

    SELECT 
      user_id, 
      SUM(points)   AS total_points,
      SUM(points=4) AS no_of_fours,
      SUM(points=3) AS no_of_threes,
      SUM(points=2) AS no_of_twos
    FROM Table1
    GROUP BY user_id;
    

    Demo here.

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

Sidebar

Related Questions

Suppose I have the following table GAME match_id, user_id, score 1, 10, 45 1,
I have the following table structure: ID, User_ID, DateTime Which stores a user id
I have a users table with the following information users (id, username, password, email,
I have a mysql table with the following columns: id (autoincremented primary key) user_id
My Schema I have the following tables table notes/example values ------------------------------------------------ users ( id
I have the following table called stores id store zip 1 Market 1 01569
I have the following table id score start_time end_time 1 60 25 30 2
I have the following table: id INT (PRIMARY) score INT I'd like to know,
I have the following used to create a dummy high score table if if
I have a MSSQL table stores that has the following columns in a table:

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.