📜  mysql select and count left join - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:25.999000             🧑  作者: Mango

代码示例1
select
  t.Topic,
  t.Title,
  count(distinct s.starID) as StarCount,
  count(distinct m.User) as UserCount,
  count(distinct m.messageID) as MessageCount
from
  Topics t
  left join Messages m ON m.Topic = t.Topic
  left join Stars_Given s ON s.Topic = t.Topic
group by
  t.Topic,
  t.Title