sql >> Database teknologi >  >> RDS >> Oracle

Maksimum af gennemsnit

Uden CTE'er kan du:

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 kunne du gøre:

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. Anmodning indstillet i Concurrent Manager

  2. Bruger COUNT i GROUP_CONCAT

  3. hvordan henter man data fra tre eller flere tabeller?

  4. Referenceværdi for seriel kolonne i en anden kolonne under samme INSERT