Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   Most popular values in a recordset (http://www.velocityreviews.com/forums/t800233-most-popular-values-in-a-recordset.html)

 Eddie 12-13-2005 10:27 AM

Most popular values in a recordset

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 12-13-2005 10:33 AM

Re: Most popular values in a recordset

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" <Eddie@discussions.microsoft.com> a écrit dans le message de
news:6E3D789C-6726-4A13-B9FD-29358FD81C88@microsoft.com...
> 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 12-13-2005 10:58 AM

Re: Most popular values in a recordset

I fogort the GROUP BY Value clause...

--

"Patrice" <nobody@nowhere.com> a écrit dans le message de
news:OktbnC9\$FHA.228@TK2MSFTNGP12.phx.gbl...
> 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" <Eddie@discussions.microsoft.com> a écrit dans le message de
> news:6E3D789C-6726-4A13-B9FD-29358FD81C88@microsoft.com...
> > 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

>
>

 All times are GMT. The time now is 02:22 PM.