Velocity Reviews > Most popular values in a recordset

# Most popular values in a recordset

Eddie
Guest
Posts: n/a

 12-13-2005
Hi
I am trying to soleve the following problem using an asp recordset (connects
to sql)
A column in the recordset contains integers between 1 and 5. I am trying to
find a way of concluding which integer is the most common, then the second
most common, then the third. (In the event of a tie, the higher integer
'wins'). Hence if in the record set there were 5 1s, 4 2s, 7 3s, 1 4 and 5
5s the output would be Most popular = 7, send most popular = 1 and third most
popular = 5. I am familiar with rhe recordset objects ie looping through the
records etc

Eddie

Patrice
Guest
Posts: n/a

 12-13-2005
It would be easier to just issue a SQL request such as :

SELECT Value, COUNT(*) FROM MyTable ORDER BY 2 DESC,Value DESC

Else you could loop the recordset and store the count in an array....

--

"Eddie" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
> Hi
> I am trying to soleve the following problem using an asp recordset

(connects
> to sql)
> A column in the recordset contains integers between 1 and 5. I am trying

to
> find a way of concluding which integer is the most common, then the second
> most common, then the third. (In the event of a tie, the higher integer
> 'wins'). Hence if in the record set there were 5 1s, 4 2s, 7 3s, 1 4 and

5
> 5s the output would be Most popular = 7, send most popular = 1 and third

most
> popular = 5. I am familiar with rhe recordset objects ie looping through

the
> records etc
>
> Eddie

Patrice
Guest
Posts: n/a

 12-13-2005
I fogort the GROUP BY Value clause...

--

"Patrice" <(E-Mail Removed)> a écrit dans le message de
news:OktbnC9\$(E-Mail Removed)...
> It would be easier to just issue a SQL request such as :
>
> SELECT Value, COUNT(*) FROM MyTable ORDER BY 2 DESC,Value DESC
>
> Else you could loop the recordset and store the count in an array....
>
> --
>
> "Eddie" <(E-Mail Removed)> a écrit dans le message de
> news:(E-Mail Removed)...
> > Hi
> > I am trying to soleve the following problem using an asp recordset

> (connects
> > to sql)
> > A column in the recordset contains integers between 1 and 5. I am

trying
> to
> > find a way of concluding which integer is the most common, then the

second
> > most common, then the third. (In the event of a tie, the higher integer
> > 'wins'). Hence if in the record set there were 5 1s, 4 2s, 7 3s, 1 4

and
> 5
> > 5s the output would be Most popular = 7, send most popular = 1 and third

> most
> > popular = 5. I am familiar with rhe recordset objects ie looping

through
> the
> > records etc
> >
> > Eddie

>
>