簡(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)航:
           
          主站蜘蛛池模板: 和平区| 无为县| 兰州市| 鄂温| 汝州市| 休宁县| 吉首市| 务川| 泰州市| 枞阳县| 宁陵县| 曲阜市| 鲁甸县| 灵宝市| 冷水江市| 金堂县| 邻水| 祁门县| 广宗县| 贵港市| 新沂市| 彭阳县| 化州市| 灯塔市| 墨竹工卡县| 丽水市| 绿春县| 洛阳市| 易门县| 达拉特旗| 呈贡县| 抚顺市| 潢川县| 弥勒县| 贡嘎县| 德江县| 晋宁县| 比如县| 荔波县| 平果县| 韶关市|