query of queries with avg()

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default query of queries with avg()

    cfmx 6.1
    when i use avg() in a query of queries it rounds the results (actually rounds
    results down)...so i'm wondering if i am doing this incorrectly. here is my
    example:

    <cfscript>
    q1="select * from mbr";
    q2="select avg(mbrlos) as alos from mbr";
    q3="select avg(mbrlos) as alos from qry1";
    </cfscript>
    <h3>Query 1 (qry1)</h3> select * from mbr
    <cfquery name="qry1" datasource="qqtest">
    #q1#
    </cfquery>
    <cfdump var="#qry1#" />
    <h3>Query 2 (qry2)</h3> select avg(mbrlos) as alos from mbr
    <cfquery name="qry2" datasource="qqtest">
    #q2#
    </cfquery>
    <cfdump var="#qry2#" />
    <h3>Query 3 (qry3)</h3> select avg(mbrlos) as alos from qry1
    <cfquery name="qry3" dbtype="query">
    #q3#
    </cfquery>
    <cfdump var="#qry3#" />


    output for query 1 looks like:
    query
    MBRID MBRLOS MBRNAME
    1 1 5 bob
    2 2 2 john
    3 3 1 jim
    4 4 7 sam


    output for query 2 looks like:
    query
    ALOS
    1 3.75

    output for query 3 looks like:
    query
    ALOS
    1 3



    gogl Guest

  2. Similar Questions and Discussions

    1. Need Help with Query of Queries
      I have the query "almost" there but I'm not sure exactly how to accomplish this. I need all recrods meeting the criteria from the AppliedLicense...
    2. Query of Queries
      I think that we're using 5 on both environments (not checked that though - they shouldn't be different anyway)... It seems that i've fixed it......
    3. 2 queries to 1 query
      Hello, Can somebody help me to combine these two queries into one query. <cfquery datasource="#DATAS#" name="getMainNav"> SELECT * FROM...
    4. Query of Queries in 7.0
      I am running MX 6.1 and was wondering of the QofQ problem still exists (in the new version, 7.0) where CF tries to guess at the column datatype...
    5. Query of Queries on query New type query
      In CF5 we have a page that creates a query, using queryNew and querySetCell and the like, we then used dbtype="query" and gave it's name so we could...
  3. #2

    Default Re: query of queries with avg()

    Not really sure since I am still new, but just as a guess could it have to do
    with you variable type. If they are stored as an INT then they will be
    averaged as an INT. And INT only does whole numbers.

    Sorry if I am not close at all.

    PeteMares Guest

  4. #3

    Default Re: query of queries with avg()

    PeteMares is correct. I don't know if there is a way to change the data type
    of the column once it is in a query object. If MBRLOS was a character data
    type, you would have gotten an error message on qry3, but not on qry2. You can
    get the decimal results from QoQ by changing the database data type to decimal
    or doing this.

    select avg(mbrlos * 1.0) as alos from qry1


    eastinq Guest

  5. #4

    Default Re: query of queries with avg()

    perfect. thank you both. i will try this out agains my real dataset and see how it goes. this looks very promising.
    cheers.
    gogl 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