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!

Display a value in the column only if the count is greater than 1

2738487May 1 2015 — edited May 1 2015

I need to return a value in the column only if the the count is greater than 1 of that same column.

Example table:

                                                                                             

FOOD_TYPEITEMCOST_TO_BUYSELL_PRICE
Ice CreamChocolate0.502.00
Ice CreamVanilla0.502.00
Ice CreamStrawberry0.502.00
ChickenWings2.005.00
BeefSteaks8.0015.00
BeefRoast10.0018.00

In this example I want to select the FOOD_TYPE, ITEM, SUM(COST_TO_BUY) AND SUM(SELL_PRICE), but I only want to select the ITEM if there are more than 1 items in the FOOD_TYPE.

I have tried all manners of grouping and even including the a case statement in the select as follows:

CASE

WHEN (COUNT(DISTINCT ITEM) > 1)

THEN ITEM

ELSE ''

END

However, this is negated when I do the grouping because it forces me to use ITEM as a group and I cannot use the whole case statement in the GROUP BY because it has an aggregate function.

Please help!

This post has been answered by Etbin on May 1 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 29 2015
Added on May 1 2015
5 comments
7,572 views