For Loop

D

D

Dear all, got a problem stuck here...

Given:

Title No_of_Download
A 6
B 8
C 9
D 10
E 0
F 1

I wanna display 5 result from the above table starting from the most no
of download, meaning Title E will not be display. How do i do it using a
For Loop???

Regards
cheers
 
M

Maarten

RS.OPEN "SELECT * FROM MyTable WHERE No_of_Download > 0 ORDER BY
No_of_Download ASC"

DO WHILE NOT RS.EOF
RESPONSE.WRITE RS("letter") & " - " & RS("No_of_download")
RS.MOVENEXT
LOOP

RS.CLOSE
 
M

Maarten

If you wish only the 5 most downloaded

RS.OPEN "SELECT TOP 5 * FROM MyTable WHERE No_of_Download > 0 ORDER BY
No_of_Download ASC"
 
B

Bob Barrows [MVP]

D said:
May i know what is the code use for descending?? ASC is for acsending

In Access and SQL Server, the keyword is DESC. It may be different in other
databases depending on their degree of conformance to standard sql..

Bob Barrows
 
D

Dave Anderson

Maarten wrote (and I repaired the order):
RS.OPEN "SELECT * FROM MyTable WHERE No_of_Download > 0 ORDER BY
No_of_Download ASC"

While I agree that the best solution is to bring back only the desired
records, this does not produce the desired outcome. One alternative:

SELECT Title, No_of_Download FROM MyTable WHERE Title IN (
SELECT TOP 5 Title FROM MyTable ORDER BY No_of_Download DESC
) ORDER BY Title ASC

In any case, neither solution meets the requested criterion: [For loop].
Should the data source not be so flexible, I can envision many looping
solutions, but none with a single loop. The closest I could come up with:

For each [Title]
Insert node into a binomial heap,
using an inverse key on [No_of_Download]
Next

Follow that up with 5 EXTRACT-MIN operations. This, of course, suffers from
the same problem as Maarten's solution -- it is ordered by frequency rather
than title**.

If JScript is the scripting language, I suppose we could use a clever
Array.sort().slice().sort() technique to avoid explicit looping entirely.




**Beyond the overhead needed to construct a binomial heap, that is.

--
Dave Anderson, waxing academic

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top