Skip to main content
Participant
August 4, 2010
Answered

3 Lowest integer of a structure

  • August 4, 2010
  • 1 reply
  • 658 views

Hello,

I have a struct:


32       3.33333333333
38       25
46       30
56       6.06060606061

The first col is the id and the 2nd col is percent.

I want to get the 3 lowest percent from the struct.


    This topic has been closed for replies.
    Correct answer Steve Sommers

    I would attack this problem from the query side. Run another query like this:

    <cfquery name="qHighest3" ...>

         select top 3 [id], [hourly_counter] ,[leads_per_day], [hourly_counter]/[leads_per_day]*100.00 as [pcnt] from [sales]
         order by [pcnt] desc

    </cfquery>

    This was written and tested using MS-SQL. You may have to make adjustments if you are using something else.

    1 reply

    Inspiring
    August 4, 2010

    Where did the structure come from?

    Participant
    August 4, 2010

    It is coming from a loop.

    I did

    <cfset percent = structnew() />

        <cfloop query="querynamehere">
            <cfset percent[#id#] =  #hourly_counter# / #leads_per_day# * 100 />
        </cfloop>

    Steve SommersCorrect answer
    Legend
    August 4, 2010

    I would attack this problem from the query side. Run another query like this:

    <cfquery name="qHighest3" ...>

         select top 3 [id], [hourly_counter] ,[leads_per_day], [hourly_counter]/[leads_per_day]*100.00 as [pcnt] from [sales]
         order by [pcnt] desc

    </cfquery>

    This was written and tested using MS-SQL. You may have to make adjustments if you are using something else.