从mysql数据库中选择相似的值 [英] select similar values from mysql database
本文介绍了从mysql数据库中选择相似的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MySQL
数据库中有几个数据.在我的表中有一个名为 rank 的列.我想要的是当有人输入一个等级说 25
然后结果应该在相似(+ 或 -)等级 LIMIT
到 10
上显示名称来自表.
I have several data s in MySQL
database. In my table there is a column called rank. what I want is when some one enter a rank say 25
then the result should display names on similar(+ or -) ranks LIMIT
to 10
from table.
例子
mathew - 25
john - 26
joe - 25
stewart - 27
kelly - 24
brandon -23
magy - 22 .......etc.
谢谢马修
推荐答案
你可以利用 MySQL 的 between
和 limit
子句:
You can make use of the MySQL's between
and limit
clause for this:
$range = 5; // you'll be selecting around this range.
$min = $rank - $range;
$max = $rank + $range;
$limit = 10; // max number of results you want.
$query = "select * from table where rank between $min and $max limit $limit";
这篇关于从mysql数据库中选择相似的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文