Computing.Net > Forums > Database > select statement help!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

select statement help!

Reply to Message Icon

Name: bismarkcount
Date: November 5, 2007 at 12:03:07 Pacific
OS: Winxp
CPU/Ram: intel/ 1gb
Product: Dell
Comment:


Hello!! i need some help in building a sql server select statement:

i have a table with these columns and info:

product_id | quantity
------------------------
prod1 | 2
prod1 | 4
prod2 | 4
prod3 | 3
prod2 | 2
prod2 | 1


i need to build a statement in order to have each product and how many items of the product i have in existence (sum of quantities of each occurrence of a product). so the query result would look like this:


product_id | quantity
------------------------
prod1 | 6
prod2 | 7
prod3 | 3


any help will be appreciated.

thnx!!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 5, 2007 at 19:31:44 Pacific
Reply:

I don't speak SQL Server, but this is the general select command you are looking for:

select product_id, sum(quantity) from product_table
group by product_id
order by product_id


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: select statement help!

SQL Select statement help www.computing.net/answers/dbase/sql-select-statement-help/26.html

if statement help pls www.computing.net/answers/dbase/if-statement-help-pls/407.html

selecting a row from a table www.computing.net/answers/dbase/selecting-a-row-from-a-table/97.html