You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most SQL implementations don't have a PRODUCT() aggregate and window function, but it can be emulated easily as such:
-- Aggregate function
exp(sum(log(arg)))
-- Window function
exp(sum(log(arg)) OVER window_specification)
This only works for strictly positive numbers. If zero and negative numbers should be supported, this approach could be used:
WITH v(i) AS (VALUES (-2), (-3), (-4), (-5))
SELECT
CASE
WHEN SUM (CASE WHEN i <0 THEN -1 END) % 2<0
THEN -1
ELSE 1
END * EXP(SUM(LN(ABS(i)))) multiplication2
FROM v;
Most SQL implementations don't have a
PRODUCT()
aggregate and window function, but it can be emulated easily as such:This only works for strictly positive numbers. If zero and negative numbers should be supported, this approach could be used:
See: https://blog.jooq.org/2018/09/21/how-to-write-a-multiplication-aggregate-function-in-sql
The text was updated successfully, but these errors were encountered: