簡(jiǎn)易代碼之家

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            157 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks

          數(shù)據(jù)表結(jié)構(gòu)及數(shù)據(jù):


          要統(tǒng)計(jì)的報(bào)表格式:


          SQL語(yǔ)句:

          1.只統(tǒng)計(jì)最右邊的合計(jì)人數(shù):
          select t.addr,
                sum( case when(t.type='0') then 1 else 0 end ) as "甲流人數(shù)",
                sum( case when(t.type='1') then 1 else 0 end ) as "流感人數(shù)",
                sum( case when(t.type='2') then 1 else 0 end ) as "它病人數(shù)",
                count(*) as "合計(jì)人數(shù)"
          from test t
          group by t.addr;
          2.最右邊和下邊的合計(jì)都統(tǒng)計(jì):
          (select t.addr as "區(qū)域",
                sum( case when(t.type='0') then 1 else 0 end ) as "甲流人數(shù)",
                sum( case when(t.type='1') then 1 else 0 end ) as "流感人數(shù)",
                sum( case when(t.type='2') then 1 else 0 end ) as "它病戶數(shù)",
                count(*) as "合計(jì)人數(shù)"
          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) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 府谷县| 南阳市| 咸宁市| 页游| 柞水县| 车致| 麻城市| 洪泽县| 谷城县| 德阳市| 上蔡县| 天等县| 余江县| 土默特左旗| 泰兴市| 石阡县| 雅江县| 平阳县| 宁津县| 宜都市| 江源县| 会泽县| 渭南市| 文安县| 米易县| 资溪县| 桑日县| 原阳县| 韩城市| 沙洋县| 萨迦县| 阿巴嘎旗| 白水县| 巴林左旗| 德兴市| 淳化县| 佛山市| 英吉沙县| 东至县| 连城县| 寿光市|