distinct函数作用于多列 count是不能统计多个字段的,下面的SQL在SQL Server和Access中都无法运行。
select count(distinct name, id) from A;
若想使用,请使用嵌套查询,如下:
select count(*) from (select distinct xing, name from B) AS M;
参考资料: https://www.cnblogs.com/kelly1314/p/10830136.html
SELECT
DATE_FORMAT(submit_time, '%Y%m') as month,
round(count(distinct uid, DATE_FORMAT(submit_time, '%y%m%d')) / count(distinct uid),2) as avg_active_days,
count(distinct uid) as mau
FROM exam_record
where submit_time IS NOT NULL
and year(submit_time) = 2021
group by DATE_FORMAT(submit_time, '%Y%m');