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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:27:23+00:00 2026-05-31T09:27:23+00:00

I have the following Table named Order Orders Table ___________________________________________________ orderiD | userId |

  • 0

I have the following Table named Order

Orders Table
___________________________________________________
orderiD | userId | OrderType | Order_Date | Amount
________|________|___________|____________|________
1          1          0         12/12/2009    1
2          1          1         13/12/2009    2
3          1          1         14/12/2009    3
4          2          0         12/12/2009    4
5          2          1         16/12/2009    2
6          1          0         14/12/2009    5
7          2          1         17/12/2009    4
8          2          0         10/12/2010    2
___________________________________________________

I need to create query which returns user id with maximum SUM of purchases.

I tried the following

Select MAX(GRP.sumAmmount), o.userId join
(Select SUM(o.Amount) as sum_ammount, o.userId as UID from Orders GROUP BY(o.userID)) as GRP on o.userId=GRP.UID GROUP BY(GRP.UID)

But I believe I’m missing something.

Can you help?

  • 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-31T09:27:25+00:00Added an answer on May 31, 2026 at 9:27 am

    If I understand your question correctly, you want to return the UserID which has the maximum SUM (total) of purchases. So the above records will result:

    UserID  Total Amount
      2         12
    

    And the simpliest solution would be:

    SELECT UserID, SUM(AMOUNT) as TotalAmount
    FROM Orders
    GROUP BY UserID
    ORDER BY TotalAmount DESC
    LIMIT 1
    

    I’m ready to edit this if I’m wrong. 🙂
    (PS: Please add your desired result)

    Thanks.

    UPDATE 1

    Derived from you query:

      Select  MAX(SUM(o.Amount)) as sum_ammount, 
              o.userId as UID 
        FROM  Orders o
    GROUP BY  o.userID
    ORDER BY  sum_ammount DESC
       LIMIT  1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named with Sales having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i
I have a database with a table named order . When i run php
I have the following table in SQL Server 2000: TABLE_NAME | COLUMN_NAME | TYPE_NAME
Let's say I have the following table: CustomerID ParentID Name ========== ======== ==== 1
I have the following table: $sql = CREATE TABLE received_queries ( sender_screen_name varchar(50), text
I have a the following table with rows: =============================================== id| name | group1 |
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL
I have the following query: select column_name, count(column_name) from table group by column_name having
I have a Name table with the columns NameID Name TypeID With the following
I have a row of entities stored in a mysql table; entity table order

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.