--To get the nth row value
Select Type, Price from
(
Select TYPE, Price, RowNum , (z.RowNum % 5) as RowMod from
(
Select TYPE, Price, RowNum from
(
Select *, Row_Number() Over(Order By Model ASC) as RowNum from
(Select a.Model, a.TYPE, b.Price from Product a Left Join
(Select distinct p.Model, Avg(Price) Price from Product p inner join PC pc
on p.Model=pc.model Group by p.Model
Union
Select distinct p.Model, Avg(Price) Price from Product p inner join Laptop l
on p.Model=l.model Group by p.Model
Union
Select distinct p.Model, Avg(Price) Price from Product p inner join Printer pr
on p.Model=pr.model Group by p.Model
) b on a.Model=b.Model
) x
) y
) z
) FinalTable
Where RowMod=0
--------------------------------------------------------------------------
--To get the nth row value
Select TYPE, Price from
(
Select *, Row_Number() Over(Order By Model ASC) as RowNum from
(Select a.Model, a.TYPE, b.Price from Product a Left Join
(Select distinct p.Model, Avg(Price) Price from Product p inner join PC pc
on p.Model=pc.model Group by p.Model
Union
Select distinct p.Model, Avg(Price) Price from Product p inner join Laptop l
on p.Model=l.model Group by p.Model
Union
Select distinct p.Model, Avg(Price) Price from Product p inner join Printer pr
on p.Model=pr.model Group by p.Model
) b on a.Model=b.Model
) x
) z where RowNum=5
No comments:
Post a Comment