开发者

Adding a row value more than once to STDEV()

开发者 https://www.devze.com 2023-02-26 18:43 出处:网络
I have the following table: rowNumber | amount | count | |1| 1000|2| |2| 1500|3| |3| 1750|3| |4| 2000|1|

I have the following table:

| rowNumber | amount | count |
|    1      | 1000   |   2   |
|    2      | 1500   |   3   |
|    3      | 1750   |   3   |
|    4      | 2000   |   1   |

Now if I want to get the stdev how can I make the amount of the row 1 be inserted in the function's expression twice, the amount of the row 2 be inserted 3 times and so on... Right now each amount is inserted in a temp table the necessary times and we get the stdev from that table, but I want to see if the开发者_C百科re is a better and more efficient way to do so.

Thanks.


You could join onto a numbers table

SELECT STDEV(amount)
FROM YourTable JOIN Numbers ON N  <= YourTable.[count]

or write a custom CLR aggregate that takes both parameters and does the corresponding calculation.

0

精彩评论

暂无评论...
验证码 换一张
取 消