我只检索此查询中的10个最新结果,然后导致它们从最新到最旧排序,但我希望它们从最旧到最新显示。我尝试使用subselect查询执行此操作,但在执行此操作时无法正确检索结果。现在我试图通过像这样的循环向后退步来做到这一点
for i=ubound(arr,2) to 0 step -1
这仍然是从0到最后一个元素的数组,因为正在创建的图表仍然显示降序日期元素。我该如何解决这个问题,还是有更好的方法来解决这个问题?谢谢!
Dim data()
Redim data(doccount)
label=""
strSQL = "Select TOP 10 DATEPART(m, thedate),DATEPART(d, thedate),DATEPART(yyyy, thedate),DATEPART(hh, thedate),DATEPART(mi, thedate), servicestatus from [ServiceUptime] order by thedate desc"
'Response.write(strSQL)
Set rs = objConnection.Execute(strSQL, ,adCmdText)
if not (rs.bof or rs.eof) then
arr = rs.getrows()
''Create Data set
for i=0 to ubound(arr,2)
if i = ubound(arr,2) then
for j=0 to doccount
data(j) = data(j) &"["& i &","& arr(j+5,i) &"]"
next
else
for j=0 to doccount
data(j) = data(j) &"["& i &","& arr(j+5,i) &"],"
next
end if
next
''Create x axis Labels
if ubound(arr,2)>9999 then
''There are too many points
''Attempt to only use 5
Response.write(ubound(arr,2))
unit = Round(ubound(arr,2)/5,0)
for c = 0 to unit*5 Step unit
label = label &"["& c &",'"& monthArr(arr(0,c)) &" "& arr(1,c) &", "& arr(2,c) &", "& arr(3,c) &"':"& arr(4,c) &"'],"
next
else
''There are not enough points.
''Use them all
for i=ubound(arr,2) to 0 step -1
if i = 0 then
label = label &"["& i &",'"& monthArr(arr(0,i)) &" "& arr(1,i) &" "& arr(2,i) &" "& arr(3,i) &":"& arr(4,i) &"']"
else
label = label &"["& i &",'"& monthArr(arr(0,i)) &" "& arr(1,i) &", "& arr(2,i) &" "& arr(3,i) &":"& arr(4,i) &"'],"
end if
next
end if
''Create mouse over labels
moLabel = "moArr = new Array(" & ubound(arr,2) & ");"
for i=ubound(arr,2) to 0 step -1
moLabel = moLabel & "moArr[" & i & "]='" & monthArr(arr(0,i)) &" "& arr(1,i) &", "& arr(2,i) &", "& arr(3,i) &":"& arr(4,i) &"';"
next
else
dateNow = Date
dateYest = DateAdd("d",-1,dateNow)
for j=0 to doccount
data(j) = "[0,0],[1,0]"
next
label = "[0,'"&monthArr(DatePart("m",dateNow))&" "&DatePart("d",dateNow)&", "&DatePart("yyyy",dateNow)&"'][1,'"&monthArr(DatePart("m",dateYest))&" "&DatePart("d",dateYest)&", "&DatePart("yyyy",dateYest)&"']"
moLabel = "moArr = new Array(2); moArr[0]='" & monthArr(DatePart("m",dateNow))&" "&DatePart("d",dateNow)&", "&DatePart("yyyy",dateNow) &"';"& "moArr[0]='" & monthArr(DatePart("m",dateYest))&" "&DatePart("d",dateYest)&", "&DatePart("yyyy",dateYest) &"';"
end if
答案 0 :(得分:2)
尝试使用子查询:
SELECT TOP 10 * FROM (
SELECT DATEPART(m, thedate),DATEPART(d, thedate),DATEPART(yyyy, thedate),DATEPART(hh, thedate),DATEPART(mi, thedate), servicestatus
FROM [ServiceUptime]
ORDER BY thedate DESC)