0

我需要获得视频的平均评分,对于该视频,有一个名为发布日期的字段,所以我需要在发布日期之前和发布日期之后获得评分,

现在我有查询仅在视频发布日期之前获得评级,如下所示

select d.mth Month,
  coalesce(avg(t.rating), 0) Rating
from 
(
  select 1 mth union all
  select 2 mth union all
  select 3 mth union all
  select 4 mth union all
  select 5 mth union all
  select 6 mth union all
  select 7 mth union all
  select 8 mth union all
  select 9 mth union all
  select 10 mth union all
  select 11 mth union all
  select 12 mth 
) d
left join wp_fatalcut_videos_rating t
  on d.mth = month(t.ratingdate)
where d.mth in (1,2,3,4,5,6,7,8,9,10,11,12) and videoid='3192763' and ratingdate <=  '2013-10-09 00:00:00'
group by d.mth

我需要在同一查询中获得“2013-10-09 00:00:00”之后的视频发布后的评级,这可能吗?

4

1 回答 1

1

你能做到这一点吗?如果我理解你正确:

select d.mth Month,
  coalesce(avg(t.rating), 0) Rating,
  coalesce(avg(tafter.rating), 0) RatingAfter
from 
(
  select 1 mth union all
  select 2 mth union all
  select 3 mth union all
  select 4 mth union all
  select 5 mth union all
  select 6 mth union all
  select 7 mth union all
  select 8 mth union all
  select 9 mth union all
  select 10 mth union all
  select 11 mth union all
  select 12 mth 
) d
left join wp_fatalcut_videos_rating t
  on d.mth = month(t.ratingdate) 
  AND t.videoid='3192763' and t.ratingdate <=  '2013-10-09 00:00:00'
left join wp_fatalcut_videos_rating tafter
  on d.mth = month(tafter.ratingdate) 
  AND tafter.videoid='3192763' and tafter.ratingdate >=  '2013-10-09 00:00:00'
where d.mth in (1,2,3,4,5,6,7,8,9,10,11,12)
group by d.mth

我认为这是不必要的

where d.mth in (1,2,3,4,5,6,7,8,9,10,11,12)

因为表格中没有月份,mth例如 0,13 或 14。对吗?

于 2013-11-15T06:55:22.527 回答