小编典典

MySQL COUNT DISTINCT

mysql

我正在尝试收集昨天在我的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登录数?


阅读 362

收藏
2020-05-17

共1个答案

小编典典

 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
2020-05-17