0

我有一个简单的 MySQL 查询,如下所示:

 SELECT * ,
 ( MATCH (table.get) AGAINST('playstation ' IN BOOLEAN MODE) ) 
+ ( table.get LIKE '%playstation%') AS _score 
FROM table 
JOIN users on table.id_user = users.id
 WHERE table.expire_datetime > 1375997618
 HAVING _score > 0 
ORDER BY RAND(table.id) ,_score DESC ;

如果我在 MySQL 中运行此查询,它通常返回多于 1 条记录,现在我想限制 1 条并随机获取其中一条,并不总是相同的记录。

是否可以?

4

3 回答 3

2
select * from <my_table> 
ORDER BY RAND()
LIMIT 4
于 2013-08-08T21:44:30.377 回答
1

您将停止播种随机数生成器。我的猜测是它正在返回遇到的第一个表 id,因此这些数字是按相同的顺序生成的:

 SELECT * ,
 ( MATCH (table.get) AGAINST('playstation ' IN BOOLEAN MODE) ) 
+ ( table.get LIKE '%playstation%') AS _score 
FROM table 
JOIN users on table.id_user = users.id
 WHERE table.expire_datetime > 1375997618
 HAVING _score > 0 
ORDER BY RAND()
LIMIT 1;
于 2013-08-08T21:44:49.843 回答
1

据我了解问题,_score?试试这个:

Select * FROM (
   ***your sql query***
) as t
ORDER BY RAND()
LIMIT 1
于 2013-08-08T21:47:39.450 回答