An aggregate product function

Oracle SQL query to multiply aggregate values.

Assume you have a table of a bill of materials (BOM):

BOM(ItemId, ParentItemId, Name, QtyPerParent)

Let's say that you need to get a count of child items to produce some root item. For this reason you need to multiply all QtyPerParent values in the production chain. Note that all ItemId's are unique. Here is the select:

select exp(sum(ln(QtyPerParent)))
from (
select ItemId, QtyPerParent
from BOM
starting with ItemId = p_ChldItem
connect by prior ParentItemId = ItemId
minus
select ItemId, QtyPerParent
from BOM
starting with ItemId = p_RootItem
connect by prior ParentItemId = ItemId)

For More Information

  • What do you think about this tip? E-mail the editor at tdichiara@techtarget.com with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize--submit your tip today!
  • Ask your technical Oracle questions--or help out your peers by answering them--in our live discussion forums.
  • Check out our Ask the Experts feature: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

This was last published in July 2002

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close