如何获得mysql随机整数范围?
我正在尝试为我在 1 到 60 之间选择作为计时器的每一行生成一个随机整数.
I am trying to generate a random integer for each row I select between 1 and 60 as timer.
SELECT downloads.date, products.*, (FLOOR(1 + RAND() * 60)) AS timer
我已经搜索并不断提出这个 FLOOR 函数,以了解如何在一个范围内选择一个随机整数.这给了我每一行的 1.我错过了什么?
I have searched and keep coming up to this FLOOR function as how to select a random integer in a range. This is giving me a 1 for every row. What am I missing?
我使用的是 mysql 5.0.75
I am on mysql 5.0.75
这是我认为可能是嵌套问题的其余查询
Heres the rest of the query I belive it might be a nesting issue
SELECT *
FROM (
SELECT downloads.date, products.*, FLOOR(1 + (RAND() * 60)) AS randomtimer,
(
SELECT COUNT( * )
FROM distros
WHERE distros.product_id = products.product_id
) AS distro_count,
(SELECT COUNT(*) FROM downloads WHERE downloads.product_id = products.product_id) AS true_downloads
FROM downloads
INNER JOIN products ON downloads.product_id = downloads.product_id
) AS count_table
WHERE count_table.distro_count > 0
AND count_table.active = 1
ORDER BY count_table.randomtimer , count_table.date DESC LIMIT 10
推荐答案
这对我有用.你的mysql版本可能吗?
This is working for me. Your mysql version maybe?
SELECT id, (FLOOR( 1 + RAND( ) *60 )) AS timer
FROM users
LIMIT 0 , 30
相关文章