'How to divide dataset by grouping data?
I have a table with column of Depth, it ranges from 0 to 1000m with interval of 1m. I like to group them into every 10m with average value for each 10m to save time. How to do it? Thank you so much.
Here is my code without grouping on depth column.
Also wondering does this reducing num of data rows will increase query SPEED?
start='2022-01-01'
end='2022-03-01'
sql =
f""" SELECT
WELL_NAME, ROUND(OBV_TIME,'DDD') as "Date",
DEPTH, AVG(TEMPERATURE) as "TEMPERATURE"
FROM
TEMPERATURE_V
WHERE
AREA_NAME = 'Lake' AND WELL_NAME = '{well}'
AND OBV_TIME >= TO_DATE('{start}', 'YYYY-MM-DD')
AND OBV_TIME <= TO_DATE('{end}','YYYY-MM-DD')
AND DEPTH>={dts_well_depth_min}
GROUP BY
WELL_NAME, ROUND(OBV_TIME,'DDD'), DEPTH """
Solution 1:[1]
I found a solution using 10*trunc(depth/10,0) and it works.
SELECT
WELL_NAME,
OBV_TIME,
10*TRUNC(DEPTH/10,0) as "DEPTH_10",
AVG(TEMPERATURE) as "TEMPERATURE"
FROM TEMPERATURE_V
WHERE
AREA_NAME = 'Lake'
AND WELL_NAME = '{well}'
AND OBV_TIME >= TO_DATE('{start}', 'YYYY-MM-DD')
AND OBV_TIME <= TO_DATE('{end}', 'YYYY-MM-DD')
AND DEPTH>={dts_well_depth_min}
GROUP BY WELL_NAME, OBV_TIME, 10*TRUNC(DEPTH/10,0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | roudan |
