SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

r-a-l-p-h
Starting Member

Philippines
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 ...

khtan
In (Som, Ni, Yak)

Singapore
17438 Posts

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



KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.08 seconds. Powered By: Snitz Forums 2000