Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default average days

    I have a db with two colums create_date and finish_date. What I would like to
    do is take the datediff of each row , add them togehter, then divide by number
    of rows. I can get a list the datediffs for each row and I know I need to get
    them into an array, then use ArrayAvg to get my result. I just can't get my
    head around getting the array populated. Any tips, help, suggestions would be
    nice. Thanks.

    Jason

    JoeyTMann Guest

  2. Similar Questions and Discussions

    1. #39560 [NEW]: Inconsistent behaviour of strtotime when days > days in month
      From: php at colin dot guthr dot ie Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Date/time related Bug...
    2. Calculating a moving average
      Hi, I need to calculate a moving average and I would like to do it with SQL, or a Pg function built for this purpose. I'm on Pg 7.4. Is this...
    3. average using lingo
      i need a huge hand with something i need to write a function to calculate the average of a sequence and return the result. however it should only...
    4. sar on solaris 9 does not give average
      Pros, I was wondering if there is a way to get sar print the Average of CPU (Actually anything) on a Solaris 9 box? For example: On a solaris...
    5. Calculate Running Average
      Hi everybody.I'm Facing a ploblem to calculate running average.I am explaining the scenario. In my table there are two column only 1.Name...
  3. #2

    Default Re: average days

    Maybe something like this (MS SQL):

    select AVG(DATEDIFF(d, create_date, finish_date)) from your_table group by key_field

    Mr Black Guest

  4. #3

    Default Re: average days

    after banging my head against the wall for awhile I came up with...

    <cfoutput>
    <cfquery name="gettime" datasource="#DSN#">
    select create_date,finish_date
    from tickets
    where assigned_to='#attributes.tech#'
    and status='closed'
    </cfquery>
    </cfoutput>

    <cfset myArray = ArrayNew(1)>
    <cfloop query="gettime">

    <cfset temp= arrayappend(myArray,datediff('d',create_date,finis h_date))>

    </cfloop>

    <cfoutput>
    Average is #round(ArrayAvg(myarray))# days for #attributes.tech# to close a
    tag.
    </cfoutput>

    which worked nicely. Not very neat, but it works.


    JoeyTMann Guest

  5. #4

    Default Re: average days

    Wow, you must really like doing things the hard way. What was wrong with the
    suggestion by Mr Black?

    select AVG(DATEDIFF(d, create_date, finish_date))

    or even

    select SUM(DATEDIFF(d, create_date, finish_date))/count(*)

    should give you your results without all of the array stuff. Oh well...

    Phil

    paross1 Guest

  6. #5

    Default Re: average days

    Yeah I know, I am learning.
    JoeyTMann Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139