?
Solved

select ABS (SUM) question

Posted on 2004-11-05
2
Medium Priority
?
998 Views
Last Modified: 2006-11-17
i have a survey that dumps the results to a mysql database....fome time to time we will have anywhere from 12 responses to over 700+. the survey choices range from 1-6 with six being highest (1-6 = very dissatisifed - very satisfied)

one of the survey metrics is "give me % for all those answers 3 (satisfied) or higher" which in mysql translates to:

SELECT ABS( SUM( Q1 >3  )  /21  )...etc.

as i have the query right now it works great...the problem lies in the fact, as stated earlier...the number of responses varies each time and the "/21" of the query SELECT ABS( SUM( Q1 >3  )  /21  ) will change often....without having to go and rewrite the query each time...is there a way to use the COUNT feature in mysql to populate the "/XXX" part of the query?

thanks


full query
------------------------
SELECT ABS( SUM( Q1 >3  )  /21  ) , ABS( SUM( Q2 >3  )  /21  ) , ABS( SUM( Q4 >3  )  /21  ) ,ABS( SUM( Q5 >3  )  /21  ),ABS( SUM( Q6 >3  )  /21  ),ABS( SUM( Q6 >3  )  /21  )  
FROM metrics
0
Comment
Question by:nriddock
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 12508142
Does
SELECT ABS( SUM( Q1 >3  )  / COUNT(Q1)  ) , ABS( SUM( Q2 >3  )  /COUNT(Q1)  ) , ABS( SUM( Q4 >3  )  /COUNT(Q1)  ) ,ABS( SUM( Q5 >3  )  /COUNT(Q1)  ),ABS( SUM( Q6 >3  )  /COUNT(Q1)  ),ABS( SUM( Q6 >3  )  /COUNT(Q1)  )  FROM metrics

not work ??
0
 

Author Comment

by:nriddock
ID: 12508165
perfect...thanks for the quick response
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question