我们的仪表板上显示了前十名视频列表。有时我们会遇到这样一种情况,一位用户发布了 6 个视频,并且所有视频都进入了前十名(观看次数最多)。我的老板只想显示前十名中任何一名成员的前两名。
如何做到这一点。这是我用来提取数据的脚本:
SELECT a.MediaID,
COUNT(a.MediaID) AS TimesViewed
FROM MediaViewLog a
INNER JOIN MemberVideo b ON b.MemberVideoID = a.MediaID
INNER JOIN Member c ON c.MemberID = b.MemberID
WHERE a.ViewDate BETWEEN '5/25/2013 10:04:23 AM' AND '12/12/2050 11:59:59 PM'
AND a.MediaType = 'V'
AND b.CreateDate > '5/25/2013 10:04:23 AM'
AND c.SBIcon = 'N'
GROUP BY a.MediaID
MediaViewLog 包含以下数据:
+----------------+---------+-----------+-------------------------+
| MediaViewLogID | MediaID | MediaType | ViewDate |
+----------------+---------+-----------+-------------------------+
| 3336 | 7033 | V | 2013-05-26 03:36:52.573 |
+----------------+---------+-----------+-------------------------+
| 3337 | 7037 | V | 2013-05-26 04:22:16.682 |
+----------------+---------+-----------+-------------------------+
| 3338 | 12356 | A | 2013-05-26 03:36:52.573 |
+----------------+---------+-----------+-------------------------+
| 3339 | 7102 | V | 2013-05-26 07:12:25.428 |
+----------------+---------+-----------+-------------------------+
| 3340 | 7058 | V | 2013-05-26 08:02:27.003 |
+----------------+---------+-----------+-------------------------+
| 3341 | 7033 | B | 2013-05-26 03:36:52.573 |
+----------------+---------+-----------+-------------------------+
在“会员”表中,每个媒体都与一个会员相关联。“MemberID”是主键
任何想法,如果任何成员不止一个,我如何才能提取前 2 个,作为前 10 名的一部分。
任何帮助将不胜感激。
谢谢!