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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:38:57+00:00 2026-06-01T06:38:57+00:00

Is it possible to order return rows with a criteria on a sum group

  • 0

Is it possible to order return rows with a criteria on a sum group ?

For example, my data are :

Id     Price     Product     Category
1      12        Book1       Car
2      1         Book2       Art
3      8         Book3       Car
4      7         Book4       Art
5      11        Book5       Car
6      24        Book6       Bridge

As the sum of Car books is 31, the sum of Art books is 8 and the sum of Bridge books is 24, I would like to have the following result (Car first, then Bridge and then Art):

Id     Price     Product     Category
1      12        Book1       Car
3      8         Book3       Car
5      11        Book5       Car
6      24        Book6       Bridge
2      1         Book2       Art
4      7         Book4       Art

On the other hand, I would like to add other Order by criteria (in the example, “Product” criteria).
I have tried many things using ORDER BY and GROUP BY but it always aggregate my results.

Thanks for 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-06-01T06:38:59+00:00Added an answer on June 1, 2026 at 6:38 am

    You could do something like this:

    select 
      l.* from table l
    inner join (
      select category, sum(price) as total from table group by category
    ) r
    on l.category = r.category
    order by r.total, <some_other_column>
    

    This is the procedure I followed:

    1. find the subtotals
    2. join the original table to the subtotals
    3. order the original table by those subtotals
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How is it possible to return rows with an accumulate sum for a row
I want to return multiple rows in case statement. is it possible? or is
Is it possible to order results in SQL Server 2005 by the relevance of
Is it possible to order an NSMutableArray where it's values are NSStrings? I'm looking
Possible Duplicate: Elements order - for (... in ...) loop in javascript Assume you
Possible Duplicate: Ordering by the order of values in a SQL IN() clause With
in order to keep as few SQL statements as possible, I want to do
How is it possible to change the displayed order of columns from a DataTable?
Is it possible to change the order of parameters to sprintf ? like sprintf(
Is it possible to retrieve items from a Python dictionary in the order that

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.