Access数据库
查询表:
ID Name AllCount
1 张三 50
2 李四 50
3 王五 50
4 噶个 48
5 按时 48
6 地发 32
7 老牛 32
8 老杨 26
9 老裘 25
........
.
需要达到的效果是:
执行SQL1 需要返回 AllCount 最大数的其中一条,且只要一条
ID Name AllCount
1 张三 50
执行SQL2
返回 AllCount 第二大数的其中一条,且只要一条
ID Name AllCount
4 噶个 48
执行SQL3
返回 AllCount 第三大数的其中一条,且只要一条
ID Name AllCount
6 地发 32
(其中SQL1.SQL2.SQL3都需要修改,因为记录不唯一时,就会得到空记录或不唯一记录)
參考答案:1、SQL1="SELECT * FROM 数据表 Order By AllCount Desc"
rs Open SQL1,CONN,3,3
Do while noe rs.eof
t=t+1
if t=1 then
a1=rs("ID")
a2=rs("Name")
a3=rs("AllCount")
end if
rs.movenext
loop
2、SQL2="SELECT * FROM 数据表 Order By AllCount Desc"
rs Open SQL2,CONN,3,3
r=1
Do while noe rs.eof
if x>rs("AllCount") and r=1 then
r=r+1
a1=rs("ID")
a2=rs("Name")
a3=rs("AllCount")
end if
x=rs("AllCount")
rs.movenext
loop
3、SQL3="SELECT * FROM 数据表 Order By AllCount Desc"
rs Open SQL3,CONN,3,3
r=1
Do while noe rs.eof
t=t+1
if x<rs("AllCount") and y<rs("AllCount") and r=1 then
r=r+1
a1=rs("ID")
a2=rs("Name")
a3=rs("AllCount")
end if
if t=1 then x=rs("AllCount")
y=rs("AllCount")
rs.movenext
loop