簡易代碼之家

            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 閱讀(472) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 淮安市| 大丰市| 从江县| 龙里县| 松潘县| 濮阳县| 安溪县| 永善县| 星子县| 高安市| 安阳市| 兴业县| 万盛区| 张掖市| 长寿区| 无为县| 金溪县| 广西| 会宁县| 大新县| 新民市| 尼勒克县| 呼和浩特市| 安徽省| 乌苏市| 丘北县| 根河市| 慈利县| 定州市| 文登市| 叙永县| 万载县| 稻城县| 青铜峡市| 宁德市| 双流县| 仪陇县| 蒙自县| 德令哈市| 临泉县| 丽水市|