Retrieve Rank from sqlite table

后端 未结 2 807
再見小時候
再見小時候 2020-12-16 21:45

Say I have a table in an sqlite DB with two fields: name and age.

Bob|40
Rob|50
Zek|60

How can I query the sqlite table for Zek and determi

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 22:17

    You can use a subquery to count the number of people with a higher age, like:

    select  p1.*
    ,       (
            select  count(*) 
            from    People as p2
            where   p2.age > p1.age
            ) as AgeRank
    from    People as p1
    where   p1.Name = 'Juju bear'
    

提交回复
热议问题