Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 27th, 2004, 12:35 PM
MCannon MCannon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 4 MCannon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old September 27th, 2004, 02:44 PM
MCannon MCannon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 4 MCannon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Totaling Columns without Redundent Data


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT