SQL - How to find the highest number in a column?

前端 未结 15 1062
借酒劲吻你
借酒劲吻你 2020-12-30 18:25

Let\'s say I have the following data in the Customers table: (nothing more)

ID   FirstName   LastName
-------------------------------
20   John        Macken         


        
15条回答
  •  半阙折子戏
    2020-12-30 19:08

    You can also use relational algebra. A bit lengthy procedure, but here it is just to understand how MAX() works:

    E := πID (Table_Name)
    E1 := πIDID >= ID' ((ρID' E) ⋈ E)) – πIDID < ID’ ((ρID' E) ⋈ E))

    Your answer: Table_Name ⋈ E1

    Basically what you do is subtract set of ordered relation(a,b) in which a<b from A where a, b ∈ A.

    For relation algebra symbols see: Relational algebra From Wikipedia

提交回复
热议问题