【问题标题】:Total minutes streamed within 60 days from launch?发布后 60 天内流式传输的总分钟数?
【发布时间】:2021-10-11 16:42:51
【问题描述】:

我需要在发布之日起的前 60 天内找到每个标题的总播放分钟数:

xx 表:

title_id 整数
minutes_streamed 浮动
streamstartdate 日期(yyyymmdd hh:ss)

yy 表:

类型 varchar
launch_date 日期(yyyymmdd hh:ss)

SELECT xx.title_id, yy.genre, SUM(xx.minutes_streamed) AS total_minutes
  FROM xx
  JOIN yy
    ON xx.titleid = yy.titleid
 WHERE xx.streamstartdate BETWEEN yy.launch_date + 60 
   AND yy.launch_date
 GROUP BY 1, 2  

这是采取/任何其他更“优雅”的方法的正确方法吗?

【问题讨论】:

  • 别管“方法”——即使是语法错误。在 Oracle 中,您不能 group by 1, 2 并期望 1 和 2 扩展为 select 中的表达式。您可以为order by(在投影步骤之后处理 - select 步骤)执行此操作,但您不能为group by 执行此操作,它在投影之前而不是之后处理。逻辑上不可能。

标签: sql oracle oracle12c


【解决方案1】:

你的方法很好,但是这个逻辑不成立:

WHERE xx.streamstartdate between yy.launch_date+60 and yy.launch_date

between 的限制必须是 和 。所以:

WHERE xx.streamstartdate between yy.laucn_date and yy.launch_date+60

【讨论】:

  • 没有足够的街头信誉来投票,但谢谢,答案对我有帮助!
  • @Victor 。 . .作为问题的 OP,您可以接受答案。
猜你喜欢
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
  • 2018-07-11
  • 2020-07-04
  • 2019-02-22
  • 2015-06-04
  • 2017-08-24
  • 1970-01-01
相关资源
最近更新 更多