zoukankan      html  css  js  c++  java
  • 统计多个维度的百分比

                                                         
    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 
  • 相关阅读:
    字母统计
    特殊乘法
    一年的第几天
    找中位数
    查找学生信息
    Hdu 1009 FatMouse' Trade
    Hdu 1012 u Calculate e
    Hdu 1005 Number Sequence
    Hdu 1008 Elevator
    Hdu 1003 Max Sum
  • 原文地址:https://www.cnblogs.com/chongyao/p/13390084.html
Copyright © 2011-2022 走看看