Used SqlServer.
Create and fill in the test table:
create table #t (product char, price int) insert #t values ('A', 10), ('B', 20), ('C', 45), ('D', 47), ('E', 10), ('F', 60), ('G', 15), ('H', 15), ('I', 90)
Request:
select distinct first_value(product) over(partition by num order by num) as [products], avg(price) over (partition by num) as [avg] from ( select product, price, (row_number() OVER(ORDER BY product) - 1 ) / 3 as [num] from #t ) as temp
I suspect that the request is highly inefficient. On the implementation plan, three sorting. I hope someone will bring the best option.
Option proposed by i-one in the comments:
select min(product) as [products], avg(price) as [avg] from ( select product, price, (row_number() OVER(ORDER BY product) - 1 ) / 3 as [num] from #t ) as temp group by num
Judging by the implementation plan, this query is more efficient.
productscolumn. - Alexander Petrov