Day 1 = 2%

Day 2 = -0.7%

Day 3 = -1.20%

Day 4= -1.05%

How would I achieve this in SQL? A Python Pandas solution is also welcome

Thanks!!

]]>If anyone want to reads about SQL server aggregate functions here is the link

aggregate function in sql server ]]>

You need to multiply the quantity times the parent quantity times the grandparent quantity times the great grand parent quantity….etc.

I was able to get all the parents at all levels with one query. Then, I have local quantity of each row. Now, condense them at get the product. This will break with zeros however.

]]>Right. That’s my experience, that there’s rarely an overlap between heavy math and things one does in SQL.

]]>I’d be interested to hear about real-world examples which make use of this PRODUCT method.

]]>I’m sure with not too much trouble you could find an example of multiplying an integer by a float, and getting a result which is X-0.0000000000001 instead of just X, such that if you cast that as an integer it will round down. When dealing with floats and ints it is important to ROUND instead of CAST.

This method of PRODUCT is just fine. It’s the handling of data types that has caused the stackoverflow question.

]]>