簡易代碼之家

            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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 景泰县| 乐业县| 奉贤区| 兴文县| 阆中市| 达孜县| 拉萨市| 海原县| 巧家县| 宣威市| 永州市| 三门峡市| 巫山县| 安仁县| 凌海市| 凤城市| 深水埗区| 博野县| 台中市| 林州市| 阿城市| 邮箱| 都江堰市| 永清县| 治县。| 道真| 张家港市| 六枝特区| 海兴县| 宜黄县| 泸西县| 时尚| 喀喇沁旗| 那坡县| 怀集县| 稻城县| 邵阳市| 阳新县| 寿光市| 松江区| 米泉市|