There is a table name Top_Up
. Its current snapshot is:
表名为Top_Up。它目前的快照是:
When I run query SELECT * FROM Top_Up WHERE Top_up_ID = (round(random() * 9 ) + 1);
on it, I am getting random result. Sometimes it is returning with two tuples, sometimes no tuples and sometime one tuple.
当我运行查询SELECT * FROM Top_Up WHERE Top_up_ID =(round(random()* 9)+ 1);在它上面,我得到随机的结果。有时它会返回两个元组,有时没有元组,有时还有一个元组。
To debug I run the query Select (round(random() * 9 ) + 1);
and it is always returning only one tuple in the result.
要调试我运行查询Select(round(random()* 9)+ 1);并且它总是在结果中只返回一个元组。
Why I am getting this vague and random result?
为什么我得到这个模糊和随机的结果?
1 个解决方案
#1
3
Round is being calculated per row. Try this:
每行计算一轮。尝试这个:
SELECT TOP 1 * FROM Top_Up ORDER BY (round(random() * 9 ) + 1);
If you run your test against your table you should see a much different result:
如果你对你的桌子进行测试,你会看到一个非常不同的结果:
Select (round(random() * 9 ) + 1) FROM Top_Up `
If you just want a random record I would go with:
如果你只想要一个随机记录,我会选择:
SELECT TOP 1 * FROM Top_Up ORDER BY NEWID()
#1
3
Round is being calculated per row. Try this:
每行计算一轮。尝试这个:
SELECT TOP 1 * FROM Top_Up ORDER BY (round(random() * 9 ) + 1);
If you run your test against your table you should see a much different result:
如果你对你的桌子进行测试,你会看到一个非常不同的结果:
Select (round(random() * 9 ) + 1) FROM Top_Up `
If you just want a random record I would go with:
如果你只想要一个随机记录,我会选择:
SELECT TOP 1 * FROM Top_Up ORDER BY NEWID()