我有users
桌子
id | email | website
1 [email protected] google.com
2 [email protected] google.com
3 [email protected] yahoo.com
4 [email protected] yahoo.com
还有一张groups
桌子
id | group | user_id | created
1 group1 1 2018-06-06
2 group2 2 2018-06-06
3 group3 3 2018-09-09
4 group4 4 2018-06-06
我需要website
对每created
一天进行计数,因此上述内容将在2018-06-06上为google.com提供2 个
IE,
website | count | date
google.com 2 2018-06-06
yahoo.com 1 2018-06-06
yahoo.com 1 2018-09-09
我将返回的行按日期分组,但1
使用以下查询对每一行进行计数
select count(distinct users.website), groups.created
from user_groups as groups
join users on users.id = groups.user_id
group by groups.created
所以我变得很简单
count(distinct users.website) | created
1 2018-06-06
1 2018-06-06
1 2018-06-06
1 2018-09-09
试试下面
select website,created,count(website) as cnt
from groups t2 join users t1 on t1.id = t2.userid
group by website, created
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句