Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: a challanege SQL request

8 views
Skip to first unread message

charles

unread,
Jun 28, 2011, 3:50:42 PM6/28/11
to
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

Robert Klemme

unread,
Jun 28, 2011, 4:19:27 PM6/28/11
to

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/

Charles Hooper

unread,
Jun 30, 2011, 6:42:39 PM6/30/11
to

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/2011/05/26/row-values-to-comma-separated-lists-an-overly-complicated-use-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.

0 new messages