sql >> Databasteknik >  >> RDS >> Oracle

Maximum av medelvärden

Utan CTE:er kan du göra:

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
                )

Med CTE:er kan du göra:

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. Hur kan jag skapa oracle apex serverside live validering utan att behöva skicka in sidan

  2. Förklara Planera kostnadssmärta

  3. Hur CTE kan hjälpa till att skriva komplexa, kraftfulla frågor:ett prestationsperspektiv

  4. Hämta DB-ägarens namn i PostgreSql