doupo5861 2014-12-09 07:08
浏览 80
已采纳

我需要一个MySQL查询来查找表中的总计数

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.

enter image description here

  • 写回答

1条回答 默认 最新

  • douye2572 2014-12-09 07:25
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办