dbTalk Databases Forums  

SQL Question

comp.databases comp.databases


Discuss SQL Question in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jonathan Kadish
 
Posts: n/a

Default SQL Question - 07-18-2003 , 02:22 PM






I have a table with multiple rows per stock item indicating multiple
suppliers and the quantity they have instock like:

Stock_no supplier_id quantity
101221 100 5
101221 101 25
101221 105 33
101222 102 12
101222 103 15
101223 105 10
101223 100 23

and I want to run a query that sums all the quantities to one row per
stock item to upload to my webserver:

stock_no quantity
101221 63
101222 27
101223 23

Any help would be much appreciated.

Thanks in advance
Jonathan Kadish

Reply With Quote
  #2  
Old   
Christopher Browne
 
Posts: n/a

Default Re: SQL Question - 07-18-2003 , 03:53 PM






kadish (AT) satelliterecords (DOT) com (Jonathan Kadish) writes:
Quote:
I have a table with multiple rows per stock item indicating multiple
suppliers and the quantity they have instock like:

Stock_no supplier_id quantity
101221 100 5
101221 101 25
101221 105 33
101222 102 12
101222 103 15
101223 105 10
101223 100 23

and I want to run a query that sums all the quantities to one row per
stock item to upload to my webserver:

stock_no quantity
101221 63
101222 27
101223 23
This is basic SQL...

select stock_no, sum(quantity) as quantity from stock_table group by stock_no;
--
wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','acm.org').
http://www.ntlug.org/~cbbrowne/rdbms.html
"A program invented (sic) by a Finnish computer hacker and handed out free
in 1991 cost investors in Microsoft $11 billion (#6.75 billion) this week."
-- Andrew Butcher in the UK's Sunday Times, Feb 20th, 1999


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.