Q
Problem solve Get help with specific problems with your technologies, process and projects.

Items with sales above $10,000.00

Let's say we have two tables, 'Orders' and 'Customers' where the fields are:

Orders
------
ItemID(PK)
Qty

Customers
---------
ItemID(FK)
CostperUnit

Now if we have to find those Item IDs whose sales figure has gone above $10,000.00, what will be the query for this?


That's a good example of where you would use the HAVING clause with a table join to calculate the quantity times cost per unit.

 select Orders.ItemID
      , sum(Qty * CostperUnit) as Sales
   from Orders
  inner join Customers
     on Orders.ItemID = Customers.ItemID
  group by
        Orders.ItemID
 having sum(Qty * CostperUnit) > 10000

For More Information


This was last published in June 2001

Dig Deeper on Oracle and SQL

PRO+

Content

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

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

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