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

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Averaging Price

Author  Topic 

r-a-l-p-h
Starting Member

1 Post

Posted - 2013-12-01 : 05:55:56
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)

17689 Posts

Posted - 2013-12-01 : 06:40:17
[code]select avg_price = sum(total_price) / sum(qty)
from yourtable[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-01 : 11:11:59
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
   

- Advertisement -