SQL SERVER provides aggregate functions such as SUM, COUNT, MAX, MIN, AVG, etc., but does not provide the function of continuous multiplication, but in the actual development process, we may use the data of continuous multiplication, so we can realize the continuous multiplication by ourselves. Writing, test data:
--Test Data if not object_id(N'Tempdb..#T') is null drop table #T Go Create table #T([num] int) Insert #T select 1 union all select 2 union all select 3 union all select 4 union all select 5 Go -- end of test data
Common implementation:
DECLARE @I BIGINT SET @I = 1 SELECT @I = @I * ISNULL([num], 1) FROM #T SELECT @I
result:
The above is the general way of writing, we can achieve the continuous multiplication form in a mathematical way:
SELECT EXP(SUM(LOG(#T.num))) FROM #T
The result is the same as above:
Above we have realized the writing method of continuous multiplication.