Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Averaging Price
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 12/01/2013 :  05:55:56  Show Profile  Reply with Quote
How to create a script in SQL that will solve this scenario.

1) I received a Ball pen.
*Qty : 5.00
*Price : 10.00
*Total Price : 50.00

2) In the next day i received again a Ball pen
*Qty : 5.00
*Price : 12.00
*Total Price : 60.00

3) Now i Release 6 Ball pen and my expected output are.
*Qty : 6.00
*Price : 11.00
*Total Price : 66.00

To get averaging Price we need to get total number of received that can give a Requested Qty. Get Total Price and Divided by Received.

Please help me guys. Thanks all

Code code code ...

In (Som, Ni, Yak)

17689 Posts

Posted - 12/01/2013 :  06:40:17  Show Profile  Reply with Quote
select avg_price = sum(total_price) / sum(qty)
from   yourtable

Time is always against us

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 12/01/2013 :  11:11:59  Show Profile  Reply with Quote
so what should be your expected output for above data?

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000