Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Basic SQL Statments

Author  Topic 

bdiddy60
Starting Member

4 Posts

Posted - 2008-02-10 : 19:07:53
I'm in a Database class and am finding it very difficult to find any outside help. I'm sure this will appear to be very basic to those of you who work in the Database field, but your help will be greatly appreciated.

INVENTORY( SKU, Description, QUANTITYOnHand, QuantityOnOrder, Warehouse)
WAREHOUSE( Warehouse, Manager, SquareFeet)

From the two tables above we're suppose to:

1.Write an SQL statement to show the Warehouse and average QunatityOnHand of all items stored in a warehouse managed by 'Smith'. Use a subquery.

2.Write an SQL statement to show the Warehouse and average QunatityOnHand of all items stored in a warehouse managed by 'Smith'. Use a join.
This is what I came up with. Please give me some feedback:

SELECT Avg(QuantityOnHand)
FROM INVENTORY
WHERE WAREHOUSE IN
(SELECT WAREHOUSE
FROM MANAGER
WHERE Manager = ‘Smith’);

2.44) SELECT Avg(QuantityOnHand)
FROM INVENTORY, WAREHOUSE
WHERE Manager = ‘Smith’

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-02-10 : 21:08:03
I think this is what the instructor is looking for:

SELECT Warehouse, AVG(QuantityOnHand) AS QuantityOnHand
FROM INVENTORY
WHERE Warehouse IN (SELECT Warehouse FROM WAREHOUSE WHERE Manager = 'Smith')
GROUP BY Warehouse

SELECT i.Warehouse, AVG(i.QuantityOnHand) AS QuantityOnHand
FROM INVENTORY i
INNER JOIN WAREHOUSE w
ON i.Warehouse = w.Warehouse
WHERE w.Manager = 'Smith'
GROUP BY i.Warehouse

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

bdiddy60
Starting Member

4 Posts

Posted - 2008-02-10 : 22:23:21
Thanks for the reply. Is it necessary to use the lower case i and w? What is their purpose?
Go to Top of Page

kiruthika
Yak Posting Veteran

67 Posts

Posted - 2008-02-10 : 23:45:32
quote:
Originally posted by bdiddy60

Thanks for the reply. Is it necessary to use the lower case i and w? What is their purpose?



Hi!
i and w are called alias name of the table.You must use.
kiruthika!
http://www.ictned.eu
Go to Top of Page
   

- Advertisement -