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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 |
| |||
| <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 |
| |||
| 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 |
| |||
| 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. |
| |||
| <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 |
| ||||
| 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 |