I have a table which shows data for each of the dates on a column, but on each of these days there are 1000 values and I would like to get the mean of these values, but do not know how to use group by with pivot.
SQL so far:
select *
from (select date_data,id, name, scenery,
(extract(month from date)-extract(month from data_date))+12*(extract(year from date)-extract(year from data_date)) as T ,simulation,value
from escen
where date_data = '30/09/2022'
and scenario in ('BASE')
)
pivot ( avg(value)
for T between 0 and 120
order by 1, 2, 3, 4;
This returns a pivoted table with the same 1000 values instead of the average value. I should group it either by id or name, but I am not sure how.
Data:
date_data|ID|Name|Scenery|N Simu|Simul| Date | Value
30/09/22 |1| A | Base | 1000 | 1 | 30/09/28 | 0,0397
30/09/22 |1| A | Base | 1000 | 2 | 30/09/28 | -0,069
I have different Scenarios and 1000 simulations for each of those. The simul column shows which number of simulation is of these 1000, and I would like to get the mean of these 1000 values for each scenario in each date.
Current results:
date_data|ID|Name|Scenery|Simul| 30/09/28 | 31/10/28
30/09/22 |1| A | Base | 1 | 0,0397 | 0,0521
30/09/22 |1| A | Base | 2 | -0,069 | -0,0222
Desired results:
date_data|ID|Name|Scenery| 30/09/28 | 31/10/28
30/09/22 |1| A | Base | avg(value) | avg(value)