Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Brain cramp on analytical functions and grouping.
I'm not totally sure I understand the problem, but maybe something like this
would serve?
<warning="air sql">
select mytable.wo, mytable.cp
from mytable, (select wo, count(*) rc
from mytable group by wo) wo_counterwhere mytable.wo = wo_counter.wo
</warning="air sql">
hth,
-Roy
Roy Pardee
Programmer/Analyst
SWFPAC Lockheed Martin IT
Extension 8487
-----Original Message-----
Sent: Wednesday, August 07, 2002 11:35 AM
To: Multiple recipients of list ORACLE-L
OK, my brain hurts. A dev wants a query to return in a peculiar sort order on 8.1.7.2, but I'm having no luck. He needs groups of rows sorted by the whole of their key values. That doesn't sound right, so maybe an example:
Table A
RI WO CP RC RN 1 W859674 A120003 3 1 2 W859674 A120004 3 2 3 W859674 A120006 3 3 4 W838796 A120000 2 1 5 W838796 A120003 2 2 6 W844656 A120000 2 1 7 W844656 A120004 2 2 8 W849769 A120000 2 1 9 W849769 A120004 2 2 10 W858835 A120000 2 1 11 W858835 A120003 2 2 12 W880717 A120003 2 1 13 W880717 A120006 2 2
In an attempt to breakdown the problem, I added columns RC and RN as "COUNT(*) OVER (PARTITION BY WO)" and "ROW_NUMBER() OVER (PARTITION BY WO ORDER BY CP)", respectively. I also added the row spacing here for clarity.
The dev would like the group of WO W858835, rows 10 and 11, immediately after WO group W838796 because the groups have the same number of rows (RC) and same values of CP within the groups.
MIN and MAX would work in this case, but if the groups are larger than two it's no guarantee of order. What I was thinking is a report column that would be the concatonation of all the CPs for the group, but since it's VARCHAR2 and not numeric, I'm not sure how that could be accomplished.
Any suggestions, including favorite beers, is more than welcome.
TIA!
Rich Jesse System/Database Administrator Rich.Jesse_at_qtiworld.com Quad/Tech International, Sussex, WI USA
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Liststo: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Liststo: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Wed Aug 07 2002 - 18:48:24 CDT
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message