簡易代碼之家

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            157 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks

          數據表結構及數據:


          要統計的報表格式:


          SQL語句:

          1.只統計最右邊的合計人數:
          select t.addr,
                sum( case when(t.type='0') then 1 else 0 end ) as "甲流人數",
                sum( case when(t.type='1') then 1 else 0 end ) as "流感人數",
                sum( case when(t.type='2') then 1 else 0 end ) as "它病人數",
                count(*) as "合計人數"
          from test t
          group by t.addr;
          2.最右邊和下邊的合計都統計:
          (select t.addr as "區域",
                sum( case when(t.type='0') then 1 else 0 end ) as "甲流人數",
                sum( case when(t.type='1') then 1 else 0 end ) as "流感人數",
                sum( case when(t.type='2') then 1 else 0 end ) as "它病戶數",
                count(*) as "合計人數"
          from test t
          group by t.addr)
          union
          (select null, sum( case when(t.type='0') then 1 else 0 end ),
                sum( case when(t.type='1') then 1 else 0 end ),
                sum( case when(t.type='2') then 1 else 0 end ),
                count(*)
          from test t);

           

          posted on 2009-11-13 15:12 Jakin.zhou 閱讀(469) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 南昌市| 绍兴市| 堆龙德庆县| 汤阴县| 瑞昌市| 保亭| 澳门| 金华市| 佛坪县| 荔浦县| 松滋市| 黄浦区| 白城市| 昭苏县| 西充县| 安徽省| 井冈山市| 东乡族自治县| 九龙坡区| 扬州市| 桑日县| 淮阳县| 洛川县| 东宁县| 沈丘县| 永平县| 莫力| 张家港市| 河南省| 大田县| 固始县| 巫山县| 文昌市| 弥勒县| 吐鲁番市| 深水埗区| 新民市| 仲巴县| 南靖县| 清河县| 博罗县|