How to return rows listed in descending order of COUNT(*)?

前端 未结 2 414
生来不讨喜
生来不讨喜 2021-01-12 12:35

I have a table called foo with these fields:

- id

- type

- parentId

I want to select a list of parent IDS, in the descending

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 13:10

    How can this be done in the most efficient way and putting the least load on the server?

    The key is the the most efficient way.

    Not a Count() for sure, but most efficient is... to read a field, which you are storing the Count result. You can update it with a trigger or after insert.

    Especially when

    There can be thousands-hundreds of thousands of records in the table

提交回复
热议问题