陷阱1 有个人 1天提交了2份卷子


解题思路

  • 使用 left 字符串截取函数拿到提交时间的年,用 substring 函数截取月份 最后使用 concat 函数拼接
    left(str,leng) 从左截取    substring(str,star,leng)
    #答案
    concat (left(submit_time,4),substring(submit_time,6,2)) as month
    

整体答案

  select concat (left(submit_time,4),substring(submit_time,6,2)) as month,
 round(count(distinct uid,date(submit_time))/count(distinct uid),2) as avg_active_days, 
 count(distinct uid) as mau  
 from exam_record where submit_time is not null and submit_time>"2021-01-01" group by month