这段代码给我最后700条记录,而不是700条随机记录。
private string strsqlcommandBeta = " select top 700 LEFT(patronvalue17, INSTR(30, patronvalue17, ' ') -1) as patronvalue1, Rnd([objectid]) AS Ran from objectaer " +
" order by objectdate desc" +
" ";
答案 0 :(得分:3)
我不在MS Access附近,但请试一试:
SELECT * FROM (
SELECT top 700 LEFT(patronvalue17, INSTR(30, patronvalue17, ' ') -1) as patronvalue1, objectdate
FROM objectaer
ORDER BY Rnd([objectid]) ()
) order by objectdate desc
Rnd([objectid])应该给你一个随机数来排序,然后你按照你想要的那样排序。
答案 1 :(得分:0)
SELECT * FROM (
SELECT top 700 LEFT(patronvalue17, INSTR(30, patronvalue17, ' ') -1) as patronvalue1, objectdate
FROM objectaer
ORDER BY newid()
) order by objectdate desc
newid()
函数生成一个随机guid,可用于对表进行排序,在每次运行时给出不同的结果。我不知道你是否真的需要外部选择,它用于按日期降序对随机项目进行排序