我在MySQL中有此查询来检查对系统的唯一访问:
SELECT COUNT(DISTINCT id_user) AS total, access_day FROM access
WHERE (access_day BETWEEN '2018-01-21' AND '2019-01-21')
GROUP BY access_day
有效!
客户要求检查其系统的每周唯一访问权限,如果用户在1周内至少访问过一次,则已经告诉他访问权限,该怎么办?我尝试过这种方式,但是数字有误:
SELECT COUNT(DISTINCT id_user) AS total, access_day FROM access
WHERE (access_day BETWEEN '2018-01-21' AND '2019-01-21')
GROUP BY WEEK(access_day)
答案 0 :(得分:0)
您尝试过吗?
示例:
SELECT FROM_DAYS(TO_DAYS(sales_time) -MOD(TO_DAYS(sales_time) -1, 7)) AS week_beginning,
SUM(gross) AS total,
COUNT(*) AS transactions
FROM sales
GROUP BY FROM_DAYS(TO_DAYS(sales_time) -MOD(TO_DAYS(sales_time) -1, 7))
ORDER BY FROM_DAYS(TO_DAYS(sales_time) -MOD(TO_DAYS(sales_time) -1, 7))
并且,如果您的业务规则说您的工作周从星期一开始,请将-1更改为-2。