Group By function in Oracle

Hi Team,
I am trying to use a simple Group by code as shown, ...But don't need to do a Group BY on ISIN..(Varchar)...But when I remove that...I get error saying not a Groupby function...Can I just do a group by based on first two columns. ?


select distinct G.CLIENT_ID,G.YEARMONTH, D.ISIN,SUM(G.ACCOUNT_CBV) as ACCOUNT_CBV, SUM(G.TOTAL_REVENUES) as TOTAL_REVENUES from GMIS G, DEPOT D 
where G.CLIENT_ID = D.CLIENT_ID 
GROUP BY G.CLIENT_ID,G.YEARMONTH,D.ISIN order by Client_ID;

Open in new window

Flex TronDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
don't use distinct when doing a group by, it's redundant

if you don't care about the isin column, then it must be unique, in which case you can use MAX or MIN to include it in the aggregation.
or, if it's not unique but you don't care which value you return, then either MAX or MIN should be sufficient anyway.


  SELECT g.client_id,
         g.yearmonth,
         MAX(d.isin) isin,
         SUM(g.account_cbv) AS account_cbv,
         SUM(g.total_revenues) AS total_revenues
    FROM gmis g, depot d
   WHERE g.client_id = d.client_id
GROUP BY g.client_id, g.yearmonth
ORDER BY g.client_id;
Haris DulicIT ArchitectCommented:
Hi,

maybe something like this:

select a.CLIENT_ID, a,YEARMONTH, a.ACCOUNT_CBV, a.TOTAL_REVENUES , b.ISIN
from (
select G.CLIENT_ID,G.YEARMONTH, SUM(G.ACCOUNT_CBV) as ACCOUNT_CBV, SUM(G.TOTAL_REVENUES) as TOTAL_REVENUES 
from GMIS G, DEPOT D 
where G.CLIENT_ID = D.CLIENT_ID 
GROUP BY G.CLIENT_ID,G.YEARMONTH
)a left join
(select distinct CLIENT_ID as CLIENT_ID, ISIN from DEPOT) b on a.CLIENT_ID=b.CLIENT_ID
 order by a.Client_ID;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sdstuberCommented:
using two queries on the same table is needlessly expensive, even if there are indexes

also, using a left join changes the functionality of the query
Flex TronDeveloperAuthor Commented:
The Issue is that the tables have different levels of granularity. In that way, it's always challenging. Will keep researching on this...but sure the answers help a ton.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.