简体   繁体   中英

I need a MySQL query for find the total count from a table

I need to find the total number of occurrence of a specific values in columns.

eg:

In the below image of my mysql table structure i have fields like essc_a1 , essc_a2 ... essc_a10 .

a1 to a10 entries coming from a group of ten questions.I need to find the number of occurrence of a value (for eg: "eg" or "S") in a1 to a10 columns.

I tried the following query but not working for me.

SELECT 
    COUNT(essc_a1,essc_a2,...,essc_a10) as count 
FROM 
    employee_satisfaction_survey_checklist 
GROUP BY 
    essc_a1, essc_a2,..., essc_a10 
WHERE
    essc_a1 LIKE '% es %' 
    OR essc_a2 LIKE '% es %' 
    OR .... essc_a10 LIKE '% es %';

Please help me.

在此处输入图片说明

Well, it's ugly, but it can be done. Would make a lot more sense to have a table of questions and a table with a single row for each response to each a question, but if you can't do that you can do something like this, extending the SUM to include all 10 columns:

SELECT SUM(IF(essc_a1 LIKE '%es%', 1, 0) + IF(essc_a2 LIKE '%es%', 1, 0))
FROM employee_satisfaction_survey_checklist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM