sql >> Database >  >> RDS >> Oracle

Maximum van gemiddelden

Zonder CTE's kunt u het volgende doen:

Select Z.Department, Z.AvgWage
From  (
        Select Department, Avg(Wage) AvgWage
        From Employees
        Group By Department
        ) As Z
Where AvgWage = (
                Select Max(Z1.AvgWage)
                From    (
                        Select Department, Avg(Wage) AvgWage
                        From Employees
                        Group By Department
                        )  Z1
                )

Met CTE's zou u het volgende kunnen doen:

With AvgWages As
    (
    Select Department
        , Avg(Wage) AvgWage
        , Rank() Over( Order By Avg(Wage) Desc ) WageRank
    From Employees
    Group By Department
    )
Select Department, AvgWage, WageRank
From AvgWages
Where WageRank = 1


  1. mysql full-text zoekfout

  2. Archieflogboekbestemmingsdirectory instellen in Oracle Database

  3. Node.js, Request, MySQL en Connection Pooling leiden tot oneindig blokkerings-/bevriezingsgedrag?

  4. Een testomgeving maken vanuit een productierepository