Skip to content
Advertisement

Combine multiple selects for statistics generation into on result set

Hey Pros,

I am far away to have good knowledge about SQL, and would ask you to give me some hints.

Currently we aggregate our data with python and I would try to switch this when possible to. (SQL (Postgresql server)

My goal is to have one statment that generate an average for two seperates column’s for specific time intervals (1 Hour, 1 Day, 1 Week, Overall) also all events in each period shoud be counted.

I can create 4 single statments for each interval but strugle how to combine this four selects into on result set.

When possbile the result should look like the data on image enter image description here

Some hints would be great, thank u

Advertisement

Answer

Consider conditional aggregation by moving WHERE logic to CASE statements in SELECT. Alternatively, in PostgreSQL use FILTER clauses.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement