sql to store aggregated R1 data