加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Oracle查询固定行数不足用0补齐

(2014-07-04 15:37:19)
标签:

体育

分类: oracle
select province
  from (select *
          from (select 'GD' as province, 0 as hrl
                  from dual
                union all
                select 'BJ' as province, 0 as hrl
                  from dual
                union all
                select 'SH' as province, 0 as hrl
                  from dual
                union all
                select 'GS' as province, 0 as hrl
                  from dual
                union all
                select 'LN' as province, 0 as hrl
                  from dual
                union all
                select 'HA' as province, 0 as hrl
                  from dual
                union all
                select 'JS' as province, 0 as hrl
                  from dual
                union all
                select 'SC' as province, 0 as hrl
                  from dual
                union all
                select 'SD' as province, 0 as hrl
                  from dual
                union all
                select 'XJ' as province, 0 as hrl
                  from dual
                union all
                select 'ZJ' as province, 0 as hrl
                  from dual
                union all
                select 'HB' as province, 0 as hrl
                  from dual
                union all
                select 'FJ' as province, 0 as hrl
                  from dual
                union all
                select 'HL' as province, 0 as hrl
                  from dual
                union all
                select 'HE' as province, 0 as hrl
                  from dual
                union all
                select 'JL' as province, 0 as hrl
                  from dual
                union all
                select 'TJ' as province, 0 as hrl
                  from dual
                union all
                select 'YN' as province, 0 as hrl
                  from dual
                union all
                select 'HN' as province, 0 as hrl
                  from dual
                union all
                select 'AH' as province, 0 as hrl
                  from dual
                union all
                select 'SX' as province, 0 as hrl
                  from dual
                union all
                select 'SN' as province, 0 as hrl
                  from dual
                union all
                select 'JX' as province, 0 as hrl
                  from dual
                union all
                select 'GZ' as province, 0 as hrl
                  from dual
                union all
                select 'NM' as province, 0 as hrl
                  from dual
                union all
                select 'GX' as province, 0 as hrl
                  from dual
                union all
                select 'CQ' as province, 0 as hrl
                  from dual
                union all
                select 'NX' as province, 0 as hrl
                  from dual
                union all
                select 'HI' as province, 0 as hrl
                  from dual
                union all
                select 'QH' as province, 0 as hrl
                  from dual
                union all
                select 'XZ' as province, 0 as hrl
                  from dual
                union all
                select 'WFQF' as province, 0 as hrl
                  from dual)
        union all (select decode(t.province,
                                null,
                                'WFQF',
                                '无法区分归属地',
                                'WFQF',
                                '广东',
                                'GD',
                                '北京',
                                'BJ',
                                '上海',
                                'SH',
                                '甘肃',
                                'GS',
                                '辽宁',
                                'LN',
                                '河南',
                                'HA',
                                '江苏',
                                'JS',
                                '四川',
                                'SC',
                                '山东',
                                'SD',
                                '新疆',
                                'XJ',
                                '浙江',
                                'ZJ',
                                '湖北',
                                'HB',
                                '福建',
                                'FJ',
                                '黑龙江',
                                'HL',
                                '河北',
                                'HE',
                                '吉林',
                                'JL',
                                '天津',
                                'TJ',
                                '云南',
                                'YN',
                                '湖南',
                                'HN',
                                '安徽',
                                'AH',
                                '山西',
                                'SX',
                                '陕西',
                                'SN',
                                '江西',
                                'JX',
                                '贵州',
                                'GZ',
                                '内蒙古',
                                'NM',
                                '广西',
                                'GX',
                                '重庆',
                                'CQ',
                                '宁夏',
                                'NX',
                                '海南',
                                'HI',
                                '青海',
                                'QH',
                                '西藏',
                                'XZ') province,
                         sum(t.h80 + t.h85 + t.h8500 + t.h5100) hrl
                    from REPORT_PROVINCE t
                   where substr(t.s_date, 1, 6) = 201405
                   group by decode(t.province,
                                   null,
                                   'WFQF',
                                   '无法区分归属地',
                                   'WFQF',
                                   '广东',
                                   'GD',
                                   '北京',
                                   'BJ',
                                   '上海',
                                   'SH',
                                   '甘肃',
                                   'GS',
                                   '辽宁',
                                   'LN',
                                   '河南',
                                   'HA',
                                   '江苏',
                                   'JS',
                                   '四川',
                                   'SC',
                                   '山东',
                                   'SD',
                                   '新疆',
                                   'XJ',
                                   '浙江',
                                   'ZJ',
                                   '湖北',
                                   'HB',
                                   '福建',
                                   'FJ',
                                   '黑龙江',
                                   'HL',
                                   '河北',
                                   'HE',
                                   '吉林',
                                   'JL',
                                   '天津',
                                   'TJ',
                                   '云南',
                                   'YN',
                                   '湖南',
                                   'HN',
                                   '安徽',
                                   'AH',
                                   '山西',
                                   'SX',
                                   '陕西',
                                   'SN',
                                   '江西',
                                   'JX',
                                   '贵州',
                                   'GZ',
                                   '内蒙古',
                                   'NM',
                                   '广西',
                                   'GX',
                                   '重庆',
                                   'CQ',
                                   '宁夏',
                                   'NX',
                                   '海南',
                                   'HI',
                                   '青海',
                                   'QH',
                                   '西藏',
                                   'XZ')))
 group by province
 order by sum(hrl) desc

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有