MySQL COUNT DISTINCT
我正在尝试收集昨天在我的CP中不同访问的次数,然后计算它们。
SELECT DISTINCT `user_id` as user,
`site_id` as site,
`ts` as time
FROM
`cp_visits`
WHERE
ts >= DATE_SUB(NOW(), INTERVAL 1 DAY)
由于某些原因,这会使用相同的站点ID提取多个结果。…我如何只提取并计算不同的site_id cp登录数?
回答:
Select Count(Distinct user_id) As countUsers
, Count(site_id) As countVisits
, site_id As site
From cp_visits
Where ts >= DATE_SUB(NOW(), INTERVAL 1 DAY)
Group By site_id
以上是 MySQL COUNT DISTINCT 的全部内容, 来源链接: utcz.com/qa/398667.html