在大多数线程之后排序类别


Order the categorys after most threads

我有两个表,一个用于categories,一个用于threads
我想要显示所有的分类,按其中的线程数排序。问题是我不知道如何做到这一点。

我cats-table

:

  • idCats
  • <
  • 名称/gh>
我threads-table

:

  • idThreads
  • 标题
  • 创建

我的线程表中的类别包含类别的id。

下面的查询将按降序给出类别名称及其对应的线程数的列表:

select
    c.name,
    COUNT(*) as cnt
from
    cats c
    left join threads t
        on  c.idCats = t.category
group by
    c.name
order by
    cnt desc