【问题标题】:Why does this timestampdiff CASE yield AVG lower than the WHEN?为什么这个 timestampdiff CASE 产生的 AVG 低于 WHEN?
【发布时间】:2016-01-19 19:31:37
【问题描述】:

我正在尝试通过源报告获取平均卸载日期,我有一个

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,否则为 Null?

【问题讨论】:

  • 你没有打电话给 AVG。

标签: mysql reporting


【解决方案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

【讨论】:

  • 愚蠢的错误 - 谢谢。是的,我在重做查询时间隔了
猜你喜欢
  • 2015-01-17
  • 1970-01-01
  • 2020-06-16
相关资源
最近更新 更多