dbTalk Databases Forums  

Help: a challanege SQL request

comp.databases.oracle.server comp.databases.oracle.server


Discuss Help: a challanege SQL request in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
charles
 
Posts: n/a

Default Help: a challanege SQL request - 06-28-2011 , 02:50 PM






All,

I have a table like this:
COL1 COL2
------------------------------
I a
I b
I c
II a
II b
III a
III b
III c


I would like to get all the col1 that data entry is the same as I.

So in this case, I has a, b, c, and III has a, b, c as well. I would
like to get III, but II.

Could somebody help?

Thanks

Reply With Quote
  #2  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Help: a challanege SQL request - 06-28-2011 , 03:19 PM






On 28.06.2011 21:50, charles wrote:
Quote:
All,

I have a table like this:
COL1 COL2
------------------------------
I a
I b
I c
II a
II b
III a
III b
III c


I would like to get all the col1 that data entry is the same as I.

So in this case, I has a, b, c, and III has a, b, c as well. I would
like to get III, but II.

Could somebody help?
Is this some kind of homework assignment? I would join the table with
an inline view which selects all COL2 where COL1 is "I". Group the
result by COL1 and select only those having a particular count.
Roughly. Note, there is a premise which is needed for this to work
properly. Left as exercise... ;-)

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Reply With Quote
  #3  
Old   
Charles Hooper
 
Posts: n/a

Default Re: Help: a challanege SQL request - 06-30-2011 , 05:42 PM



On Jun 28, 3:50*pm, charles <dshprope... (AT) gmail (DOT) com> wrote:
Quote:
All,

I have a table like this:
COL1 * * * * * *COL2
------------------------------
I * * * * * * * * * * a
I * * * * * * * * * * b
I * * * * * * * * * * c
II * * * * * * * * * *a
II * * * * * * * * * *b
III * * * * * * * * * a
III * * * * * * * * * b
III * * * * * * * * * c

I would like to get all the col1 that data entry is the same as I.

So in this case, I has a, b, c, *and III has a, b, c as well. *I would
like to get III, but II.

Could somebody help?

Thanks
If you are running a recent release of Oracle Database, take a look at
the LISTAGG function. See the example here:
http://hoopercharles.wordpress.com/2...-case-example/

LISTAGG will allow you to collapse the multiple row values from column
COL2 for each distinct value in column COL1, into a single row. Once
the multiple rows are collapsed to a single row the final processes
should be fairly straight-forward.

Charles Hooper
Co-author of "Expert Oracle Practices: Oracle Database Administration
from the Oak Table"
http://hoopercharles.wordpress.com/
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.