[英]symfony2 mysql ranking based on time interval
i'm working on symfony2 project and i have to write a query that show ranked users based on number of views of their reviews on differnets periods (weekly, monthly and all time) 我正在从事symfony2项目,我必须编写一个查询,该查询根据不同网段(每周,每月和所有时间)的评论查看次数来显示排名用户
so i have this structure : 所以我有这个结构:
user table (user) review table (review)
+---+--------+ +---+--------+------+-----+
|id |username| |id |user_id |title |desc |
+------------+ +------------+------+-----+
|5 | mark | |1 | 5 | tt | aaa |
|6 | steve | |2 | 7 | tt | aaa |
|7 | user | |3 | 6 | tt | aaa |
+---+--------+ +---+--------+------+-----+
review log view table (review_view)
+----------+--------+---------------------+
|review_id |user_id |viewed_at |
+----------+--------+---------------------+
|1 | 1 | 2014-06-05 15:12:00 |
|2 | 2 | 2014-06-05 15:12:00 |
|3 | 8 | 2014-06-05 16:12:00 |
|1 | 1 | 2014-06-05 15:12:00 |
|2 | 2 | 2014-06-07 20:12:00 |
|3 | 10 | 2014-06-07 15:12:00 |
|1 | null | 2014-06-07 15:12:00 |
|2 | 2 | 2014-06-09 15:12:00 |
|3 | 3 | 2014-06-09 15:12:00 |
|1 | 1 | 2014-06-09 15:12:00 |
|2 | 20 | 2014-06-09 15:12:00 |
|3 | 8 | 2014-06-03 15:12:00 |
+---+--------+------+---------------------+
the review_view table log every time user(user_id) view a review (review_id) the user_id can be null for users not logged in 用户(user_id)每次查看评论(review_id)时review_view表日志,对于未登录的用户,user_id可以为null
the problem is i have to display them like showed in the following picture 问题是我必须像下图所示显示它们
description of the picture: - the weekly,monthly and all time are tabs - the red arrows is to say if the ranking has changed from last week 图片描述:-每周,每月和所有时间都是选项卡-红色箭头表示排名是否与上周相比发生了变化
So any idea to do it with symfony2 or mysql ? 所以有什么想法可以用symfony2或mysql吗?
thanks 谢谢
You can use case
and group by
to get the values for each user for the last two time periods. 您可以使用
case
和group by
来获取最近两个时间段内每个用户的值。 this will certainly produce a select statement that can't be written easily in Doctrine, you might be able to do it with DQL. 这肯定会产生一个选择语句,该语句不能用Doctrine轻松编写,您可以使用DQL做到这一点。
Another choice would be to write a view in MySQL and then use that as if it was a table in your Symfony program. 另一种选择是在MySQL中编写一个视图,然后将其用作Symfony程序中的表。 Views used to have terrible performance in MySQL, but that may have improved.
视图曾经在MySQL中具有糟糕的性能,但是可能已经得到改善。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.