Member of the LearnItFirst.com Video Training Network | LearnSqlServer.com | SQL SSIS Training | SQL Programming Tutorials |
LearnSqlServer.com Forums LearnSqlServer.com
Welcome Guest Search | New Posts | Members | Log In | Register

How to query total stock quantity base on product price? Options
mudidotnet
Posted: Tuesday, July 22, 2008 11:03:45 AM
Rank: Newbie

Joined: 7/22/2008
Posts: 3
Points: -91
Location: Bali
Helo,

I have a case study, but have no idea to solve it in sql:
i realy appreciate if someone can show me the light....

prdId | price | qty

1------- 10------ 1
1------- 20-------1
1------- 20-------3

4-------30-------2
4-------30-------4

5-------30-------4


how can i write a query with return result as?:

prdId | price | qty

1-------10-------1
1-------20-------4

4-------30-------6

5-------30-------4

regards,
md5


archi
Posted: Tuesday, July 22, 2008 2:24:14 PM
Rank: Newbie

Joined: 7/22/2008
Posts: 1
Points: 3
The following query will give you the required results

select prodid,price,sum(qty) as qty from <tablename> group by prodid,price
mudidotnet
Posted: Tuesday, July 22, 2008 6:50:38 PM
Rank: Newbie

Joined: 7/22/2008
Posts: 3
Points: -91
Location: Bali
well,
I have tried something like that before but got an error because i forgot to write the last "price"
thanks so munch archi for your help. its work good.


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
     
Don't Forget!
LearnItFirst.com
Don't Forget!
LearnSqlServe.com
 
Home | About Us | Support | Contact Us | Privacy | Site Map | Blogs Blogs Refer a Friend and Get a Free Subscription!
© Copyright 2004-2007 LearnItFirst.com LLC. All rights reserved. All trademarks remain the property of their respective owners.
This site is not affiliated in any way with the Microsoft Corporation.