add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table mytable (asofdate date, columna int, columnb int, columnc int);
insert into mytable (asofdate, columna, columnb, columnc)
values
('2021-05-25', 12, 2, 3),
('2021-05-25', 12, 2, 3),
('2021-05-25', 12, 2, 3),
('2021-05-25', 12, 1, 3),
('2021-05-25', 12, 1, 3),
('2021-05-25', 12, 1, 3);
6 rows affected
SELECT
asofdate,
SUM(monthly_return)
FROM
(
SELECT
asofdate,
ROUND(columna * 1.0 / SUM(columnb) OVER (PARTITION BY asofdate) * columnc, 4) As monthly_return
from mytable
WHERE asofdate BETWEEN '2021-05-25' AND '2021-05-26'
) subquery
GROUP BY asofdate
ORDER BY asofdate;
asofdate (No column name)
2021-05-25 24.000000000000