我需要对数据库中的一些数据进行分组,比如说我的数据是
url, siteId
abc, 1
abc, 1
abc, 2
abc, 2
abc, 2
我需要计算每个站点上URL的数量。我尝试使用GROUP BY url
和SELECT *, COUNT(url) as urlCount
,但是将所有5个分组在一起。是否可以单独使用mysql进行操作,还是需要一些PHP来格式化该数据?
分组依据,siteid
而不是分组依据url
select siteid, count(distinct url) as urlCount
from your_table
group by siteid
如果使用distinct
,则将获得唯一URL的计数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句