getting count less 0 entries

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default getting count less 0 entries

    i am building a survey site where selections are: Strongly Agree = 5 Agree = 4
    Neither Agree nor Disagree = 3 Disagree = 2 Strongly Disagree = 1 Not
    Applicable = 0 To chart output, i have done a query: <cfset catcnt = 96>
    <cfset catcnt1 = #catcnt# - 1> <cfquery name='gtavg' datasource='surveyz'
    dbtype='ODBC'> SELECT <cfloop index=catz from=1 to=#catcnt1# step=1>
    AVG(s#catz#) AS a#catz#, </cfloop> AVG(s#catcnt#) AS a#catcnt# FROM
    client_table ; </cfquery> where i loop thru table to get average of each of 96
    questions. PROBLEM.... 'Not Applicable' should not be weighed into averages
    and throws off survey. is there any way to ignore (or count non) '0' entries
    in loop? otherwise i will have to create a query for each of 96 fields... ugh!

    ranger Guest

  2. Similar Questions and Discussions

    1. Log Entries
      Can someone explain how log entries work in FMS 3? If I play one FLV file, there are 5 entries. I am starting with a clean logfile to see how...
    2. select last 4 entries
      I have the following query and output: ******** <cfquery name="qCount" datasource="database"> SELECT AVG(sleep_effic) AS Views FROM slab_diary...
    3. How can I count field entries?
      I have a series of fields on a layout that can contain either 1's or 2's. I would like to have 2 other fields that count the number of 1's and the...
    4. FWF #13--New Entries
      Hi all-- Some great new entries have been posted for this round of Fun with Fireworks by Richie B, Matthew Brown, Japes, and Craig Hartel. Stop...
    5. Listbox with entries
      Hello: Is it possible to do the following: In a list or combo box I want to enter letters and need to find the line with data entry. Thanks...
  3. #2

    Default Re: getting count less 0 entries

    small example of where clause, check your db docs to lear more

    <cfquery name="gtavg" datasource="surveyz" dbtype="ODBC">
    SELECT
    <cfloop index=catz from=1 to=#catcnt1# step=1>
    AVG(s#catz#) AS a#catz#,
    </cfloop>
    AVG(s#catcnt#) AS a#catcnt#
    where
    <cfloop index=catz from=1 to=#catcnt1# step=1>
    s#catz# <> 0
    </cfloop>
    FROM client_table ;
    </cfquery>

    kim il sung Guest

  4. #3

    Default Re: getting count less 0 entries

    Too much commas without an AND :)

    <cfquery name="gtavg" datasource="surveyz" dbtype="ODBC">
    SELECT
    <cfloop index=catz from=1 to=#catcnt1# step=1>
    AVG(s#catz#) AS [a#catz#] <cfif catz lt catcnt1>, </cfif>
    </cfloop>
    AVG(s#catcnt#) AS [a#catcnt#]
    where
    <cfloop index=catz from=1 to=#catcnt1# step=1>
    s#catz# <> 0 <cfif catz lt catcnt1> AND </cfif>
    </cfloop>
    FROM client_table ;
    </cfquery>

    Der Nickname Guest

  5. #4

    Default Re: getting count less 0 entries

    tried your ideas and seems to be one problem... remember, this is a survey and
    can be hundreds++ of rows. your loop in the WHERE statement follows the loop
    in the SELECT statement. so would loop thru all 96 fields in SELECT, 96
    times...? am i confused??? limiter '<> 0' needs to affect the SELECT
    statement as am only looping table 1 time for all AVG am i missing something
    here? also there already is a WHERE statement that i skipped to simplify
    discussion: WHERE (memdt IS NOT NULL) AND (NOT empLocation = 'test') ; tnx in
    advance

    ranger Guest

  6. #5

    Default Re: getting count less 0 entries

    Hi Ranger

    not sure if you'd be able to do this in all one query as if you put a where
    statement in of s1 <> 0 then it will knock the whole row out of the query
    statement.

    I would do one query on the database to get all the answer records and then do
    QoQ over the 96 columns to get the average for each answer.

    HTH

    Zoe

    <!--- do 1 query on database --->
    <cfquery name="getAnswers" datasource="surveyz" dbtype="ODBC">
    SELECT *
    FROM client_table
    WHERE memdt IS NOT NULL
    AND empLocation <> 'test'
    </cfquery>

    <!--- loop through all columns and get the average for each column - exclude 0
    values --->
    <cfloop index=catz from=1 to=#catcnt# step=1>
    <cfquery name="getAnswers#catz#" DBTYPE="QUERY">
    SELECT avg(s#catz#) as a#catz#
    FROM getAnswers
    WHERE s#catz# <> 0
    </cfquery>
    <CFDUMP VAR="#Evaluate('getAnswers#catz#')#" LABEL="getAnswers#catz#">
    </CFLOOP>

    zoeski80 Guest

  7. #6

    Default Re: getting count less 0 entries

    Stack your loops:
    <cfquery name="gtavg" datasource="surveyz" dbtype="ODBC">
    SELECT
    <cfloop index=catz from=1 to=#catcnt1# step=1>
    AVG(s#catz#) AS [a#catz#] <cfif catz lt catcnt1>, </cfif>
    AVG(s#catcnt#) AS [a#catcnt#]
    where
    <cfloop index=catz from=1 to=#catcnt1# step=1>
    s#catz# <> 0 <cfif catz lt catcnt1> AND </cfif>
    </cfloop>
    </cfloop>
    FROM client_table ;
    </cfquery>

    Der Nickname 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