I would need to know how to select the account after calculating the sum of their exposures. My dataset looks like:
expos account users
12 1241 2141
341 1241 5123
41 412 21
12 413 43
My expected output would be
sum(expos) account
353 1241 (sum over users on time=12)
41 412
12 413
To try to achieve this, I am currently using this code:
sel expos
, sum (expos) over (partition by account)
, account
, users
from table_1 tab1
inner join table_2 tab2
on tab1.users=tab2.users
where time=12
But the output is giving me not only the sum but also the other single values.
How can I get output shown above?
update: expos comes from table 1 and it was calculated.
I think you just want to drop users
and expos
from the group by
:
select sum(expos) over (partition by account), account
from table_1 tab1 inner join
table_2 tab2
on tab1.users = tab2.users
where time = 12
group by account