Unix Technical Forum

GROUP BY....but not on all columns

This is a discussion on GROUP BY....but not on all columns within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Greetings, I need to apply a group by in my query but not necessarily on all columns in select ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 01:03 PM
pankaj_wolfhunter@yahoo.co.in
 
Posts: n/a
Default GROUP BY....but not on all columns

Greetings,
I need to apply a group by in my query but not necessarily on all
columns in select list.

For eg:

select col1, col2, col3, col4, col5
from table_name
group by col1, col2, col3, col4

Now the requirement is to include all 5 columns but group by only
first 4

How can I achieve this? Any help would be appreciated.

TIA

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 01:03 PM
pankaj_wolfhunter@yahoo.co.in
 
Posts: n/a
Default Re: GROUP BY....but not on all columns

On Jun 17, 12:27 am, "pankaj_wolfhun...@yahoo.co.in"
<pankaj_wolfhun...@yahoo.co.in> wrote:
> Greetings,
> I need to apply a group by in my query but not necessarily on all
> columns in select list.
>
> For eg:
>
> select col1, col2, col3, col4, col5
> from table_name
> group by col1, col2, col3, col4
>
> Now the requirement is to include all 5 columns but group by only
> first 4
>
> How can I achieve this? Any help would be appreciated.
>
> TIA


Sorry...didnt provide the oracle version earlier

Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
PL/SQL Release 9.2.0.8.0 - Production

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 01:03 PM
Michel Cadot
 
Posts: n/a
Default Re: GROUP BY....but not on all columns


<pankaj_wolfhunter@yahoo.co.in> a écrit dans le message de news: 1182022067.132225.271110@n15g2000prd.googlegroups. com...
| Greetings,
| I need to apply a group by in my query but not necessarily on all
| columns in select list.
|
| For eg:
|
| select col1, col2, col3, col4, col5
| from table_name
| group by col1, col2, col3, col4
|
| Now the requirement is to include all 5 columns but group by only
| first 4
|
| How can I achieve this? Any help would be appreciated.
|
| TIA
|

Instead of posting a wrong query
post your needs in functional terms.
What do you want?

Regards
Michel Cadot


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 01:03 PM
pankaj_wolfhunter@yahoo.co.in
 
Posts: n/a
Default Re: GROUP BY....but not on all columns

On Jun 17, 1:41 am, "Michel Cadot" <micadot{at}altern{dot}org> wrote:
> <pankaj_wolfhun...@yahoo.co.in> a écrit dans le message de news: 1182022067.132225.271...@n15g2000prd.googlegroups. com...
> | Greetings,
> | I need to apply a group by in my query but not necessarily on all
> | columns in select list.
> |
> | For eg:
> |
> | select col1, col2, col3, col4, col5
> | from table_name
> | group by col1, col2, col3, col4
> |
> | Now the requirement is to include all 5 columns but group by only
> | first 4
> |
> | How can I achieve this? Any help would be appreciated.
> |
> | TIA
> |
>
> Instead of posting a wrong query
> post your needs in functional terms.
> What do you want?
>
> Regards
> Michel Cadot


Thanks for the reply Michael and sorry for that query as a demo

Here is the requirement.

We have one de-normalized table in one schema(say db2). The records
from this table needs to be populated to
a set of normalized table in another schema(say oracle). The records
are inserted into final tables using a set
of group by clause.

Means first table, in oracle schema, needs to be populated using
source table, in db2 schema, using say group by col1, col2.
Then the second table should be populated using group by col1, col2,
col3. and so on

So in short, the requirement is: populating a set of destination
tables using a single source table based on certain grouping columns

What is the way to do this?

TIA

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-08-2008, 01:03 PM
dean
 
Posts: n/a
Default Re: GROUP BY....but not on all columns

On Jun 16, 3:27 pm, "pankaj_wolfhun...@yahoo.co.in"
<pankaj_wolfhun...@yahoo.co.in> wrote:
> Greetings,
> I need to apply a group by in my query but not necessarily on all
> columns in select list.
>
> For eg:
>
> select col1, col2, col3, col4, col5
> from table_name
> group by col1, col2, col3, col4
>
> Now the requirement is to include all 5 columns but group by only
> first 4
>
> How can I achieve this? Any help would be appreciated.
>
> TIA


You will need some kind of aggregate function. You could use min(col5)
here instead of just col5.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-08-2008, 01:03 PM
Michel Cadot
 
Posts: n/a
Default Re: GROUP BY....but not on all columns


<pankaj_wolfhunter@yahoo.co.in> a écrit dans le message de news: 1182028043.276237.53400@i38g2000prf.googlegroups.c om...
On Jun 17, 1:41 am, "Michel Cadot" <micadot{at}altern{dot}org> wrote:
> <pankaj_wolfhun...@yahoo.co.in> a écrit dans le message de news: 1182022067.132225.271...@n15g2000prd.googlegroups. com...
> | Greetings,
> | I need to apply a group by in my query but not necessarily on all
> | columns in select list.
> |
> | For eg:
> |
> | select col1, col2, col3, col4, col5
> | from table_name
> | group by col1, col2, col3, col4
> |
> | Now the requirement is to include all 5 columns but group by only
> | first 4
> |
> | How can I achieve this? Any help would be appreciated.
> |
> | TIA
> |
>
> Instead of posting a wrong query
> post your needs in functional terms.
> What do you want?
>
> Regards
> Michel Cadot


Thanks for the reply Michael and sorry for that query as a demo

Here is the requirement.

We have one de-normalized table in one schema(say db2). The records
from this table needs to be populated to
a set of normalized table in another schema(say oracle). The records
are inserted into final tables using a set
of group by clause.

Means first table, in oracle schema, needs to be populated using
source table, in db2 schema, using say group by col1, col2.
Then the second table should be populated using group by col1, col2,
col3. and so on

So in short, the requirement is: populating a set of destination
tables using a single source table based on certain grouping columns

What is the way to do this?

TIA

--------------------------------------

You said how you want to achieve your need: you want to do it using "group by"
You didn't say what is the need: what you currently want to achieve using "group by"

Maybe using "group by" is not the correct way.

If it is easier for you, post an example.

Regards
Michel Cadot



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-08-2008, 01:03 PM
DA Morgan
 
Posts: n/a
Default Re: GROUP BY....but not on all columns

pankaj_wolfhunter@yahoo.co.in wrote:
> On Jun 17, 1:41 am, "Michel Cadot" <micadot{at}altern{dot}org> wrote:
>> <pankaj_wolfhun...@yahoo.co.in> a écrit dans le message de news: 1182022067.132225.271...@n15g2000prd.googlegroups. com...
>> | Greetings,
>> | I need to apply a group by in my query but not necessarily on all
>> | columns in select list.
>> |
>> | For eg:
>> |
>> | select col1, col2, col3, col4, col5
>> | from table_name
>> | group by col1, col2, col3, col4
>> |
>> | Now the requirement is to include all 5 columns but group by only
>> | first 4
>> |
>> | How can I achieve this? Any help would be appreciated.
>> |
>> | TIA
>> |
>>
>> Instead of posting a wrong query
>> post your needs in functional terms.
>> What do you want?
>>
>> Regards
>> Michel Cadot

>
> Thanks for the reply Michael and sorry for that query as a demo


That's Michel ... not Michael.

> We have one de-normalized table in one schema(say db2). ...


This is not the statement of a business requirement it is an "I want"
statement. What is the business case?

For example:
We need to aggregate, by some value, all of the ....
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com