簡易代碼之家

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

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


          網站導航:
           
          主站蜘蛛池模板: 偏关县| 双城市| 揭东县| 淅川县| 微博| 汾西县| 苗栗县| 奉贤区| 会昌县| 客服| 白朗县| 工布江达县| 清原| 南乐县| 张家港市| 胶州市| 平陆县| 临武县| 河津市| 芦溪县| 泸水县| 托克托县| 增城市| 鲜城| 河津市| 南汇区| 河曲县| 林甸县| 广昌县| 泰安市| 临清市| 江西省| 双辽市| 兴隆县| 沙雅县| 湄潭县| 鄄城县| 皮山县| 河源市| 绥滨县| 九龙县|