Friday, February 24, 2012

How to get largest 3 values from 5 columns

Hi,

I wondered if someone could help me, I'm new to defining my own SQL statements!

I am looking to extract 4 columns of data from a Access database, these columns I am pasting into a table. That I can do using the select query, and set them AS variable1 to 4.

(I am putting these variables into an ASP page)

My problem comes when I need to create an extra column which shows the best 3 results from the 4 returned data points. In excel I would use something such as =Large(CellA1:E1, 1) to give me the largest value and then so on for the largest 3, and then summate these three values.

I have pasted my code so far below:

I'd be very grateful if someone could enlighten me.

Many thanks!
__________________________________________________ ____

ResultsSQL = "SELECT *, (Round1Pts) AS Round1Points, " & _
"(Round2Pts) AS Round2Points, " & _
"(Round3Pts) AS Round3Points, " & _
"(Round4Pts) AS Round4Points, " & _
"(????) AS Best3Points " & _
"FROM " & ResultsTable & " ORDER BY (Best3Points) DESC, (DriverName) DESC"Did you try using the MAX function?

MAX(Round1Pts,MAX(Round2Pts,MAX(Round3Pts,MAX(Roun d4Pts)))) AS Best3Points
...etc...
:cool:

No comments:

Post a Comment