码迷,mamicode.com
首页 > 其他好文 > 详细

统计多个维度的百分比

时间:2020-07-28 13:56:22      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:group by   sele   img   多个   ota   class   gis   load   _id   

技术图片

 

 

                                                     
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 

 

统计多个维度的百分比

标签:group by   sele   img   多个   ota   class   gis   load   _id   

原文地址:https://www.cnblogs.com/chongyao/p/13390084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!