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

  • Home
  • SEARCH
  • 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 8577531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:10:51+00:00 2026-06-11T20:10:51+00:00

SELECT MAX( t.valuesum ) AS total, t.codebook FROM ( SELECT SUM( value ) AS

  • 0
SELECT MAX( t.valuesum ) AS total, t.codebook
FROM (
    SELECT SUM( value ) AS valuesum, codebook
    FROM stock
    GROUP BY codebook
) t
GROUP BY t.codebook

In the subquery, the output is :

b001 35,
b002 20,
b0003 11

I want to only see: b001 35. Please help me.

  • 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-11T20:10:52+00:00Added an answer on June 11, 2026 at 8:10 pm

    1st solution using where condition:

    SELECT t1.valuesum, t1.codebook
    FROM (
            SELECT SUM( s.value ) AS valuesum, s.codebook
            FROM stock s
            GROUP BY s.codebook
         ) t1
    WHERE t1.valuesum in (SELECT MAX( t2.valuesum ) AS total
                         FROM (
                                 SELECT SUM( s2.value ) AS valuesum, s2.codebook
                                 FROM stock s2
                                 GROUP BY s2.codebook
                               )t2
                         ) 
    

    SQL Fiddle Demo

    2nd solution using having condition:

    SELECT max(t1.valuesum), t1.codebook
    FROM (
            SELECT SUM( s.value ) AS valuesum, s.codebook
            FROM stock s
            GROUP BY s.codebook
         ) t1
    GROUP BY t1.codebook
    HAVING max(t1.valuesum) = (SELECT MAX( t2.valuesum ) AS total
                         FROM (
                                 SELECT SUM( s2.value ) AS valuesum, s2.codebook
                                 FROM stock s2
                                 GROUP BY s2.codebook
                               )t2
                         )
    

    SQL Fiddle Demo

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

Sidebar

Related Questions

SELECT MAX(some_field) FROM table_A GROUP BY another_field This only gets the max value of
When I run the following SQL statement: SELECT MAX(SUM(TIME)) FROM downloads GROUP BY SSN
select max( sum(duration) ),cd from rent group by cd; . ERROR 1111 (HY000): Invalid
The query is: select sum(value) from TAB where TimeStamp= { select max(TimeStamp) from TAB
SELECT MAX(crash_year) AS crash_year, COUNT(crash_year) AS COUNT FROM nyccrash GROUP BY crash_year ORDER BY
For the query: SELECT MAX(LOG_CREATION_DATE),COL_A, COL_B FROM IMPORT_LOG GROUP BY TO_CHAR(LOG_CREATION_DATE, 'MM-DD-YYYY'), COL_A, COL_B
LastAccessed=(select max(modifydate) from scormtrackings WHERE bundleid=@bundleid and userid=u.userid), CompletedLessons=(select Value from scormtrackings WHERE bundleid=@bundleid
I have table where I need to select MAX(SUM(total)) of a periods total. SELECT
SELECT MAX(verification_id) FROM VERIFICATION_TABLE WHERE head = 687422 AND mbr = 23102 AND RTRIM(LTRIM(lname))
string queryStr = select max(patient_history_date_bio) + as med_date, medication_name from biological where + (patient_id

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.