查看: 1016|回复: 2
|
如何写顺序每次都不一的sql statement?
[复制链接]
|
|
SELECT * FROM question WHERE status = 'active'
如果我这样写的话,电脑会根据questionID来顺序列出records来,有何办法可以让每一次query出来的的顺序都不一样? |
|
|
|
|
|
|
|
发表于 25-7-2005 02:43 PM
|
显示全部楼层
SELECT TOP 1 someColumn
FROM someTable
ORDER BY RAND((1000*IDColumn)
不过better way 是你在coding 中pass random number 进query.. 以C#为例子:
Random r = new Random();
int a = r.Next(100);
string sqlstmt = SELECT TOP 1 someColumn
FROM someTable
ORDER BY RAND('"+a+"'*IDColumn)
...
我想到这个方法... |
|
|
|
|
|
|
|
发表于 25-7-2005 04:51 PM
|
显示全部楼层
如果是mssql 2k的话,可以这样, (其他version不懂可不可以):
SELECT * FROM question WHERE status = 'active' order by newid() |
|
|
|
|
|
|
| |
本周最热论坛帖子
|