Home > Backend Development > PHP Tutorial > Mysql如何准确赛选(排序)出最值得推荐的信息?

Mysql如何准确赛选(排序)出最值得推荐的信息?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:50:53
Original
894 people have browsed it

若数据表(info)有如下字段:

id subject message dateline replies views istop
主题 信息 时间 回复 点击数 是否推荐

如何赛选出15天(半个月)内最值得查看/推荐的信息?

一般写法是:

SELECT id,subject,message,dateline,replies,views,istop FROM `info` WHERE istop = 1 ORDER BY replies DESC,views DESC,dateline DESC LIMIT 10;
Copy after login
Copy after login

以上赛选出来的信息,会有一个严重的BUG错误,也就是

replies 和 views 越大 越会排在前面,越往前排,replies 和 views 将会越大,所以这是一个正比,同时这样的操作将对其他信息产生不公正的影响。

现在,求一个ORDER BY 公式不因为replies 和 views 越大而越靠前的算法,

目前我能想到的是:LOG对数函数,对数不会因为replies和views越大而越大。

回复内容:

若数据表(info)有如下字段:

id subject message dateline replies views istop
主题 信息 时间 回复 点击数 是否推荐

如何赛选出15天(半个月)内最值得查看/推荐的信息?

一般写法是:

SELECT id,subject,message,dateline,replies,views,istop FROM `info` WHERE istop = 1 ORDER BY replies DESC,views DESC,dateline DESC LIMIT 10;
Copy after login
Copy after login

以上赛选出来的信息,会有一个严重的BUG错误,也就是

replies 和 views 越大 越会排在前面,越往前排,replies 和 views 将会越大,所以这是一个正比,同时这样的操作将对其他信息产生不公正的影响。

现在,求一个ORDER BY 公式不因为replies 和 views 越大而越靠前的算法,

目前我能想到的是:LOG对数函数,对数不会因为replies和views越大而越大。

如何赛选出15天(半个月)内最值得查看/推荐的信息?其实这个有比较多做法。比如通过一个时间字段也可以做到和这个比较相似。不过我想推荐是我的一个做法就是建一个字段。加上自己一个算法得出一个数直然后order by 字段 desc limit 15。这样子。我认为是比较高效的。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template