我有一张包含书籍视图的表格:
ID UserID TIME BookID
1 2 (timedate) 1
1 3 (timedate) 1
1 54 (timedate) 1
1 4 (timedate) 2
1 5 (timedate) 2
much more ....
我一直试图获取一个查询,该查询计算了图书的浏览次数,并将其从最高到最低列出。
我想这样做,所以我可以在过去一个月内展示5本具有高额观看次数的书。
非给定的工作正在发挥作用!
如果有帮助的话,我会通过一个while循环。
$gethotbookq = mysqli_query($con,"select BookID, count(*) as views
from `BOOKS_views`
where `TIME` >= '2014-05-01 00:00:00' and `TIME` < '2014-06-01 00:00:00'
group by BookID
order by views desc
limit 5") or die();
while($gethotbook = mysql_fetch_array($gethotbookq))
{
$bookid = $gethotbook['BookID'];
}
答案 0 :(得分:0)
select bookID, count(*) as views
from books
where `time` >= '2014-04-01' and `time` < '2014-05-01'
group by bookID
order by views desc
limit 5
答案 1 :(得分:0)
UserID是视图吗?
这可能有助于计算图书在图书ID中显示的次数。只要没有很多smae用户看同一本书,那么这些观点应该是非常有意义的。
SQL: How to get the count of each distinct value in a column?
接下来,您应该拥有所有booksID和视图计数的列表,并可以将视图从最高到最低排序。