1 Reply Latest reply on Jan 10, 2007 11:25 AM by Dinghus

    AVG() problem

      I have a survey where people can rate photos from 1-5, 5 being the best rating. The numbers 1-5 are radio boxes so they can only select one. The name of the radio input is the name of the picture, for instance beach, and the value is 1-5. So that code would be:

      <cfloop index="loopindex" from = "1" to = "5" step = "1">
      <input type = radio name = "beach" value = #loopindex# <cfif beach is loopindex>checked</cfif>> #loopindex#
      <input type = radio name = beach value=0 <cfif beach is 0>checked</cfif>>N/A

      The code loops through so that once someone clicks a number, it remains that way if they refresh the page. The last line is if they don't really care for it or if its NA.

      Anyways, the result page is giving me problems. I would like to do a COUNT of how many people choose each rank. So 10 people choose 5 and 3 choose 4 etc. I would also like to display this as a percent. The percent or AVG is what is giving me the problems. I tried to use this query but it didn't work:
      <cfquery datasource="photosurvey" name="getbeachrank">
      SELECT beach, Count(beach) AS count_beach, AVG(beach) AS avg_beach
      FROM photost
      GROUP BY beach
      order by beach desc

      any suggestions?