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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:05:56+00:00 2026-05-23T08:05:56+00:00

Okay, so, let’s pretend I have a table like this: Name Rank Score Adam

  • 0

Okay, so, let’s pretend I have a table like this:

Name Rank Score
Adam 1    10
Adam 2    20
Adam 3    14
Jane 2    11
Jane 3    14
Jane 4    45
Rick 1    49
Rick 3    24
Rick 5    12

I need to produce a set of results in a single table that SUMs ranks 1 and 2 in one column, and ranks 3+ in the second column. I can do this as two separate SQL statements, like so:

SELECT Name, SUM(Score) AS Score1
FROM Table
WHERE Rank < 3
GROUP BY Name

and

SELECT Name, SUM(Score) AS Score2
FROM Table
WHERE Rank > 2
GROUP BY Name

But I can’t think of any way to produce a single SQL statement that results in a single table, that might look like this:

Name Score1 Score2
Adam 30     14
Jane 11     59
Rick 49     36

Any help is appreciated. Thanks!

  • 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-23T08:05:57+00:00Added an answer on May 23, 2026 at 8:05 am

    This assumes Ranks are integers:

    SELECT Name, 
        sum(case when Rank in (1, 2) then Score else null end) as Score1,
        sum(case when Rank < 1 or Rank > 2 then Score else null end) as Score2
    FROM Table 
    GROUP BY Name 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, let's say you have something like this: <span class=image style=background-image: url('http://www.example.com/images/image1.png')></span> Every CSS
Okay, I feel like I should be able to do this, but I have
Okay let me see if I can explain this right. In wordpress we have
Okay, let's say we have a class defined like public class TestClass { private
Okay let me do a better job explaining this. Assume I have a person
Okay, so let's say I have a mysql database table with two columns, one
I have this value from database: '2009-1-1 00:00:00', okay, let me paste my code:
Let's say I have a database column 'grade' like this: |grade| | 1| |
Okay, this is quite an interesting challenge I have got myself into. My RegEx
Okay, so let's say I have a class file called Orange, and then two

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.