为什么这个timestampdiff CASE收益率AVG低于WHEN?

时间:2016-01-19 19:31:38

标签: mysql reporting

我想通过源报告获取平均卸载日期,我有一个

select i.source,u.avgday from inst i
left join ( select u.app_uid,
  case 
    when timestampdiff(day,i.app_installed_datetime, u.timestamp) > 3
    then timestampdiff(day,i.app_installed_datetime, u.timestamp) 
   else null end as avgday
  from uninst u
  inner join inst i
  on i.app_uid = u.app_uid
) as u
on u.app_uid = i.app_uid
group by i.source

为什么我在0.1-10范围内获得u.avgday结果?难道这只有AVG,其中有一个值,否则它是否为空?

1 个答案:

答案 0 :(得分:1)

我认为您打算使用AVG()聚合函数,如

  avg(case 
    when timestampdiff(day,i.app_installed_datetime, u.timestamp) > 3
    then timestampdiff(day,i.app_installed_datetime, u.timestamp) 
    end) as avgday