Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Sorting based on count of rows

FlakeDec 11 2009 — edited Feb 14 2011
Hi all,

I have a problem at hand. A table BEERS looks as follows:
BEER_NAME      QUANTITY  PRIORITY
Budweiser      17        1
Budweiser      16        2
Corona         22        1
Heineken       9         1
Heineken       11        3
Guinness       15        2
Corona         2         2
Heineken       13        2
Here, I would like to arrange Beers in cases based on priority.
No beer of different brand should go in the same case.
No beer with same brand with different priority should go in the same case.
The maximum number of bottles that can be accomodated in a case is 10.

I wish to have a query which gives the result as follows:
BEER_NAME      QUANTITY  PRIORITY

Budweiser      10        1
Budweiser      7         1
Budweiser      10        2
Budweiser      6         2
Corona         10        1
Corona         10        1
Corona         2         1
Heineken       9         1
Heineken       10        3
Heineken       1         3
Guinness       10        2
Guinness       5         2
Corona         2         2
Heineken       10        2
Heineken       3         2
How would I get this?

oracle Database Version: Enterprise Edition 10.2.0.1

Regards,
...

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 14 2011
Added on Dec 11 2009
6 comments
1,657 views