Most popular values in a recordset

Discussion in 'ASP General' started by Eddie, Dec 13, 2005.

  1. Eddie

    Eddie Guest

    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
    Eddie, Dec 13, 2005
    #1
    1. Advertising

  2. Eddie

    Patrice Guest

    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" <> a écrit dans le message de
    news:...
    > 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, Dec 13, 2005
    #2
    1. Advertising

  3. Eddie

    Patrice Guest

    I fogort the GROUP BY Value clause...

    --

    "Patrice" <> a écrit dans le message de
    news:OktbnC9$...
    > 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" <> a écrit dans le message de
    > news:...
    > > 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, Dec 13, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    4
    Views:
    11,143
    Rob McAninch
    Dec 31, 2005
  2. Ron Stephens
    Replies:
    23
    Views:
    2,835
    Ron Stephens
    Apr 12, 2004
  3. Steve
    Replies:
    0
    Views:
    375
    Steve
    Oct 25, 2004
  4. Neil Benn
    Replies:
    8
    Views:
    350
    Alex Martelli
    Oct 26, 2004
  5. tom c
    Replies:
    22
    Views:
    784
    Jon Paal
    Sep 13, 2006
Loading...

Share This Page