我有一个具有以下结构的“项目”表:
id, person_id, active
以及带有 id 和 name 列的“people”表。
我想按最活跃的项目排序并将 people.name 列加入 sql。
我试图做类似的事情,但它不起作用:
SELECT people.id, COUNT(*) as items_count
FROM items, people
WHERE items.active = true AND people.id = items.person_id
GROUP BY items.person_id
ORDER BY items_count DESC