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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:35:24+00:00 2026-06-17T23:35:24+00:00

So maybe my question title is not most relevant but I’m not good in

  • 0

So maybe my question title is not most relevant but I’m not good in sql and I will need to learn it for sure (So hint for some book would be very useful)

Anyhow I got table which has following (important) columns:

user_id,username,revenue

and records like this:

1,john,39
2,mark,53
3,philipp,7
1,john,17
2,mark,3
2,mark,100

I need to get user who has the biggest revenue, so I need to get all rows, calculate total earnings and print the user who has the biggest revenue in total.

Any hints 😉 ?

  • 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-17T23:35:25+00:00Added an answer on June 17, 2026 at 11:35 pm

    You can use ORDER BY and LIMIT :

    SELECT user_id, username, SUM(revenue) FROM table
    GROUP BY user_id /* add ', username' ONLY if two different usernames with the same user_id is a possible case */
    ORDER BY SUM(revenue) DESC
    LIMIT 0,1
    

    With this, you’ll calculate the revenue for each user, you order by decreasing total and get only the first one, so that you have the highest revenue.

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

Sidebar

Related Questions

Maybe the question sound not good or too simple. But not for me in
I'm newer in T-SQL.So maybe my question will seem naive. I need to retrieve
I'm not sure if the question title is the best one but it was
I am not sure how to describe my question (maybe title is not proper).
Maybe the title of the question is not very self-explanatory but I don't know
Not sure if it's the best title for the question... maybe someone could rename
Maybe my question title is not the right one but ill describe whats my
Maybe the question is familiar but I need an explanation in this case. Let's
Maybe my question it's a little weird, but I'm trying to build a not-so-simple
Maybe the title is not appropriate but I couldn't think of any other at

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.