Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6178505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:28:06+00:00 2026-05-24T00:28:06+00:00

I’ve got some simple survey data that I’d love to have a hand with.

  • 0

I’ve got some simple survey data that I’d love to have a hand with. I work with PHP/MYSQL.

Basically, the survey has 20 questions with 3 possible answers for each: Y, N and N/A. I want to ‘score’ each survey at the end using the formula: Y/(Y+N).

The Question: How do I actually come up with the ‘SCORE’ column at the end? Using a SQL query or using PHP (somehow)? Is there some kind of COUNTIF function in MYSQL like Excel has?

A query like: COUNTIF(“Y”, Column1:Column20) would be awesome—if it existed!

Suggestions appreciated!
(I guess I’m looking for as much procedural advice as technical with this question).

Thanks

Terry

            Q1   Q2  Q3  Q4  Q5  SCORE
            ---------------------            
Person1 -   y    n   y    n   n/a  50%
Person2 -   y    y   y    y   y    100% 
Person3 -   y    y   y    y   n/a  100%
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:28:07+00:00Added an answer on May 24, 2026 at 12:28 am

    No tricks. A long winded SUM(CASE …)

    It’d be easier with one row per question… especially when you add more questions. See First Normal Form

    SELECT
       SUM(
         CASE WHEN Q1 = 'y' THEN 1 ELSE 0 END +
         CASE WHEN Q2 = 'y' THEN 1 ELSE 0 END +
         ...
         CASE WHEN Q20 = 'y' THEN 1 ELSE 0 END
         )
       /
       SUM(
         CASE WHEN Q1 IN ('y', 'n') THEN 1 ELSE 0 END +
         CASE WHEN Q2 IN ('y', 'n') THEN 1 ELSE 0 END +
         ...
         CASE WHEN Q20 IN ('y', 'n') THEN 1 ELSE 0 END
         ),
       Person
    FROM
       myTable
    GROUP BY
       Person
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.