sql 查询分组结果集

(SELECT Count(id)                      AS per_count,
               personnel_provide_id,
               Datepart(month, returned_date) AS datepart_month
        FROM   yh_personnel
        WHERE  yh_personnel.personnel_type&60 = 32
               AND returned_date BETWEEN 2020-1-1AND 2020-12-31
        GROUP  BY personnel_provide_id,
                  Datepart(month, returned_date)) AS tb_base
SELECT (SELECT option_name
        FROM   yh_select_option
        WHERE  option_id = P_yq
               AND option_tags = PTYQ) AS subject,
       Count(CASE
               WHEN department = 11 THEN 1
             END)                        AS channel_expansion_count,
       Count(CASE
               WHEN department = 14 THEN 1
             END)                        AS channel_maintenance_count,
       Count(CASE
               WHEN department = 12 THEN 1
             END)                        AS business_count,
       Count(CASE
               WHEN department = 13 THEN 1
             END)                        AS project_count,
       Count(CASE
               WHEN department = 15 THEN 1
             END)                        AS business_support_count,
       Count(CASE
               WHEN department = 16 THEN 1
             END)                        AS assets_manager_count,
       Count(CASE
               WHEN department = 17 THEN 1
             END)                        AS clearing_count,
            count(case when P_jd=4 then 1 end ) as invalid_count,
            / as timeout_count
FROM   yh_ps_demand_application
       LEFT JOIN yh_manager
              ON yh_manager.id = yh_ps_demand_application.P_fqr
group by P_yq

 

sql 查询分组结果集

上一篇:sqlzoo练习系列(九)——群组函数之Nobel表


下一篇:HTML