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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:34+00:00 2026-05-27T17:15:34+00:00

I have query like the following SELECT a.*, b.* (SELECT ATTR1, ATTR2, sum(QUANTITY) AS

  • 0

I have query like the following

SELECT a.*, b.*

(SELECT ATTR1, ATTR2, sum(QUANTITY) AS TOTAL_QTY,
ATTR3 FROM TABLE_A
WHERE ATTR4 > 0
GROUP BY ATTR1, ATTR2, ATTR3) a,

TABLE_B b

WHERE a.ATTR1 = b.ATTR1
AND a.ATTR2 = b.ATTR2

I need to GROUP BY only ATTR1 to calculate the correct TOTAL_QTY, but the only reason I am grouping other attributes because Oracle requires that if GROUP BY clause is present then all SELECT attributes should be in the GROUP BY clause too.

This means every time I need an attribute in this query from Table_A then I need to put it in GROUP BY too. That not only looks ugly, but can have performance impact and maybe unforseen side-effect.

How do I rewrite the above query to calculate the TOTAL_QTY in each ATTR1 groups, without the GROUP BY clause?

  • 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-27T17:15:35+00:00Added an answer on May 27, 2026 at 5:15 pm

    Use Oracle analytic functions. Change the inline view for table_a to something like:

    select attr1,
           attr2,
           sum(quantity) over (partition by attr1 order by attr1) as total_qty,
           attr3
    from   table_a
    where  attr4 > 0
    

    This may need tweaking a bit, but that’s the basic idea.

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

Sidebar

Related Questions

I have the following query: SELECT o.id,o.name FROM object o WHERE ( o.description LIKE
Say I have a query like the following: SELECT * FROM users WHERE username
I have a query like the following: SELECT t1.v3, t2.v2 FROM t1 INNER JOIN
I have a query that looks like the following: SELECT someString FROM ( SELECT
I have a query that looks like the following: SELECT * FROM table WHERE
I have a query like the following: Select new mypackage.MyClass( u, max(sc.serviceDate)) from Unit
I have a query like the following: SELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Excel Driver
I have a query that looks like the following SELECT t1.Name, t2.ID, t2.name FROM
Lets assume i have a query like the following $query_search = SELECT * FROM
Basically I have a mysql query something like the following: mysql_query(SELECT n.title, v.value FROM

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.