If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Consolidation Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-27-04, 05:55
johntravoltay2k johntravoltay2k is offline
Registered User
 
Join Date: Jul 2004
Posts: 3
Consolidation Query

Just need to consolidate data in SQL

Basically the data is the spend information for many suppliers, I need to churn out just the supplier name along with a sum of their amounts spent/ volume.

I need to get FROM THIS:

Company Contract Amount Spent Volume

Shell Oil Shell891 10 100
Shell Oil Shell892 20 200
BP BP0001 50 1
BP BP0001 100 2


TO THIS

Company Amount Spent Volume
Shell Oil 30 300
BP 150 3



Etc

So I need a query that can add both the amount spent and volume and then remove DISTINCT company name rows. I understand the basics of SQL but sub-queries start to confuse me!

I would be eternally grateful for any help/ advice/ tips.

Many, many thanks!
Reply With Quote
  #2 (permalink)  
Old 07-27-04, 06:09
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Use SUM and GROUP BY as in this simple example:

SELECT deptno, SUM(sal) AS deptsal
FROM emp
GROUP BY deptno;
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 07-27-04, 07:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
please don't cross-post

http://www.dbforums.com/t1005683.html
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On