我有一个带有油价列的数据库。我的目标是根据按位置分组的“油价”列,生成一个包含显示“最小价格”,“平均价格”和“最大价格”的列的表。其中oil.frequency ='A'
这是我当前的查询
select location,
min(oil.value) over (partition BY oil.location),
max(oil.value) over (partition BY oil.location),
avg(oil.value) over (partition BY oil.location)
FROM OIL
Where oil.frequency = 'A'
GROUP BY oil.location, oil.value;
下面的图像显示了我的数据表,第二个图像显示了我希望数据如何显示。
您不需要窗口功能。只需按位置分组并汇总:
select location,
min(value),
max(value),
avg(value)
FROM OIL
Where frequency = 'A'
GROUP BY location;