我有两个具有以下结构的表
details
---------------
id | session_id
1 1
2 1
3 1
details_extra
---------------
id | details_id
1 1
2 1
3 2
4 3
我正在寻找的输出是 -
output
---------------
id | subscribers(count)
1 2
2 1
3 1
我写的查询是 -
select id, count(details_extra.id) from details left join details_extra on
details_id = details.id where session_id='1';
我得到的输出是
{id:1, subscribers:4}
任何人都可以帮忙。
编辑 - 通过添加Group By来实现它。
答案 0 :(得分:0)
尝试按ID分组:
select id, count(details_extra.id) from details left join details_extra on
details_id = details.id where session_id='1' group by id;