|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Totaling Columns without Redundent Data
Howdy Folks, I am having a tough time getting this output to format correctly and would GREATLY appreciate any help you guys could offer. I am only a student using Sql *Plus in conjunction with oracle 9i personal at home on a windows xp professional system.
Current Code and Result Table: SELECT tbl_item.item_id as ItemNumber, tbl_Item.name as Description, NVL(tbl_item_location.qty_on_Hand, '0') as OnHand, NVL(tbl_item_restock.quantity_on_order, '0') as OnOrder FROM tbl_item, tbl_item_location, tbl_item_restock WHERE tbl_item.item_id = tbl_item_location.item_id AND tbl_item_location.location_id = tbl_item_restock.location_id AND tbl_item_location.item_id = tbl_item_restock.item_id; Item Item Total Qty Total Qty Number Description On Hand On Order ---------- ------------------------------ - -------- --------- A23441 New York City Monopoly Game 11 3 Collector's Editon A23441 New York City Monopoly Game 23 16 Collector's Editon A23771 Contract: Switzerland and 2 10 Austria A23771 Contract: Switzerland and 5 5 Austria A23771 Contract: Switzerland and 6 25 Austria I am trying to create this below. The difference being I am totaling the the quantity on hand for each game instead of repeating the game with a different quantity for each location. For example the New York Monoply game on my output has 2 rows one with a quantity of 11 the other 23, totaling 34 below, I can't wrap my mind around a way to get these numbers to add without repeating the Item Name and/or the item number... ANY help would be greatly appreciated! Item Total Qty Total Qty Number Item Name On Hand On Order ------ ------------------------- ---------- ---------- A23441 New York City Monopoly 34 19 Game Collector's Edition A23771 Contrack: Switzerland and 13 40 Austria Any help or tips on this would be Awsome, Thanks guys! |
|
#2
|
|||
|
|||
|
Awnsered my own question:
SELECT tbl_item.item_id as ItemNumber, tbl_Item.name as Description, SUM(NVL(tbl_item_location.qty_on_Hand, '0')) as OnHand, SUM(NVL(tbl_item_restock.quantity_on_order, '0')) as OnOrder FROM tbl_item, tbl_item_location, tbl_item_restock WHERE tbl_item.item_id = tbl_item_location.item_id AND tbl_item_location.location_id = tbl_item_restock.location_id AND tbl_item_location.item_id = tbl_item_restock.item_id GROUP BY tbl_item.item_id ,tbl_Item.name; Took some more understanding on how the sum function worked in conjunction with group by. Thanks guys |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Totaling Columns without Redundent Data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|