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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:55:19+00:00 2026-05-30T08:55:19+00:00

I have an SQL final exam in college in a few days and I

  • 0

I have an SQL final exam in college in a few days and I have a query that’s driving me crazy! I know it’s a dumb query, but I’m just getting started and can’t figure it out.

So, there’s basicaly 2 tables, Client and Orders.

     Client           Orders
     ---------        ---------
 PK  Client_Id    PK  Order_Id
     Name             Client_Id   FK
                      Order_Total
                      Date

Now, they ask me to "List the name of the client that bought the most in 2011"

So, for what I thought, this requires on one side, that I SUM all the Order_Total and Group by Client from 2011, then from that table, select the client with the MAX() sum of order totals, and then show only the name of that client. The problem is that I can’t figure how to put all that in one query.

Hope somebody can help!


Thank you all for your very quick responses! I’m really impressed!

Now, I don’t mean to be picky or anything, but just in case my teacher doesn’t accept the "Limit" or "Select top" statement, is there any way to do this query without those?

Edit: Original code attempt ported from comments:

SELECT 
  C.NAME
FROM 
  CLIENTS C,
  ORDERS O 
WHERE 
  O.CLIENT_ID = C.CLIENT_ID 
  AND O.DATE BETWEEN '1/1/2011 00:00:00.000' and '12/31/2011 23:59:59.999' 
HAVING SUM(O.ORDER_TOTAL) >= ALL (SELECT SUM (O2.ORDER_TOTAL) FROM ORDER O2 GROUP BY O2.CLIENT_ID)
  • 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-30T08:55:20+00:00Added an answer on May 30, 2026 at 8:55 am
    SELECT T.X
     (SELECT C.NAME X, SUM(O.ORDER_TOTAL)
     FROM CLIENT C, ORDERS O
     WHERE C.CLIENT_ID = O.CLIENT_ID
       AND YEAR(O.DATE) = 2011
     GROUP BY O.CLIENT_ID
     ORDER BY 2 DESC
     LIMIT 1) T;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an SQL query that gets unread messages but I think I
I have been asking questions to get the final results for a SQL query
I have a SQL query that's fairly complicated and involves multiple subqueries and unions.
I have the following SQL query that runs fairly well, however it seems to
I have a SQL query I'm running in an ASP.NET page. The final parsed
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have SQL server 2000 dev edition. But it isn't compatible with my new
I have a sql statement that is a union of several queries which all
I have this JDBC SQL query: select * from table where TX_DATE = {d
I have some problems with writing a SQL query for MySQL. I have a

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.