统计多个维度的百分比

Posted 雨V幕

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了统计多个维度的百分比相关的知识,希望对你有一定的参考价值。

 

 

                                                     
SELECT
    CONCAT(
        ROUND(
            t1.total / t2.totalCount * 100,
            2
        ),
        \'%\'
    ) AS LocalPercent, t1.school_task_id, 0 as NonlocalPercent
FROM
    (
     select count(a.student_task_id) AS total ,school_task_id FROM tb_student_task a
     LEFT JOIN tb_student_result b on b.student_task_id=a.student_task_id
         WHERE a.task_id =8 and is_local_register=1 GROUP BY school_task_id
    ) t1,
    (
        SELECT
            count(*) AS totalCount
        FROM
            tb_student_task where is_local_register=1 and task_id=8
    ) t2 
     UNION All
        SELECT
  0 as LocalPercent , t1.school_task_id, CONCAT(
        ROUND(
            t1.total / t2.totalCount * 100,
            2
        ),
        \'%\'
    ) AS NonlocalPercent
FROM
    (
     select count(a.student_task_id) AS total ,school_task_id FROM tb_student_task a
     LEFT JOIN tb_student_result b on b.student_task_id=a.student_task_id
         WHERE a.task_id =8 and is_local_register=0 GROUP BY school_task_id
    ) t1,
    (
        SELECT
            count(*) AS totalCount
        FROM
            tb_student_task where is_local_register=0 and task_id=8
    ) t2 

 

以上是关于统计多个维度的百分比的主要内容,如果未能解决你的问题,请参考以下文章

人口稀少的百分比值的“平均”聚合

代码统计 (uustepcount)

GIT仓库代码统计

2 事实表和企业想知道一个事实占另一事实的百分比

线程池定制初探

线程池定制初探