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.
| 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 QuantityOnHandFROM INVENTORYWHERE Warehouse IN (SELECT Warehouse FROM WAREHOUSE WHERE Manager = 'Smith')GROUP BY WarehouseSELECT i.Warehouse, AVG(i.QuantityOnHand) AS QuantityOnHandFROM INVENTORY iINNER JOIN WAREHOUSE wON i.Warehouse = w.WarehouseWHERE w.Manager = 'Smith'GROUP BY i.WarehouseTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
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? |
 |
|
|
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 |
 |
|
|
|
|
|