0
如何獲得除以SQL Server 2014中最後四個值的值?SQL Server:值除以最後四個值的滾動和?
例子。如何從Value
字段獲得ValueDIVbyLastFourValues
字段?
Month|Value| ValueDIVbyLastFourValues |
---------------------------------------
1 | 1 | 1 |
2 | 1 | 1/2 |
3 | 2 | 2/4 |
4 | 2 | 2/6 |
5 | 1 | 1/6 |
6 | 7 | 7/12 |
7 | 4 | 4/14 |
壞試用
SELECT
CUSTOMER
,MONTH
,NET_VALUE_M/SUM(NET_VALUE_M) AS 'NET_VALUE_M_PROP_BY_YEAR'
FROM
MY DATA
GROUP BY LEFT(MONTH,4)
,CUSTOMER
,MONTH
,NET_VALUE_M
ORDER BY NET_VALUE_M_PROP_BY_YEAR