sql中对某个字段进行占比计算

SELECT  a.wy_type ,
        a.counts ,
        b.sums ,
        ROUND(CONVERT(DECIMAL(18, 2), a.counts) / b.sums * 100, 4) AS proportion
FROM    ( SELECT    wy_type ,
                    COUNT(h.house_id) AS counts
          FROM      p_building_house h
          WHERE     h.proj_id = 1
          GROUP BY  h.proj_id ,
                    wy_type
        ) AS a ,
        ( SELECT    COUNT(*) AS sums
          FROM      p_building_house
          WHERE     proj_id = 1
        ) AS b;

《sql中对某个字段进行占比计算》

    原文作者:北方的木
    原文地址: https://blog.csdn.net/q1923408717/article/details/115348991
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞