Home > Database > Mysql Tutorial > body text

oracle中使用decode进行数据的列转换为行的试验

WBOY
Release: 2016-06-07 17:40:15
Original
932 people have browsed it

如何将以下数据格式的数据转换为初始化格式如下:1市政府房产1232省政府房产..

如何将以下数据格式的数据转换为
初始化格式如下:
1    市政府    房产    1    2    3
2    省政府    房产    4    3    4
3    肥东    房产    5    4    5
4    肥西    房产    6    5    7
5    长风    房产    7    7    8
6    淮南    房产    8    9    5
7    市政府    汽车    1    2    3
8    省政府    汽车    4    3    4
9    肥东    汽车    5    4    5
10    肥西    汽车    6    5    7
11    长风    汽车    7    7    8
12    淮南    汽车    8    9    5
13    肥西    奢侈品    6    5    7
14    长风    奢侈品    7    7    8
15    淮南    奢侈品    8    9    5
16    市政府    贵重首饰    1    2    3
17    省政府    贵重首饰    4    3    4
18    肥东    贵重首饰    5    4    5
需要转变为
                        房产                    汽车                    奢侈品                    奢侈品       
       PRO_TYPE    场次    销售价    佣金    场次    销售价    佣金    场次    销售价    佣金    场次    销售价    佣金
1    淮南        8        9        5        8        9        5        8        9        5           
2    肥东        5        4        5        5        4        5                                5        4        5
3    市政府        1        2        3        1        2        3                                1        2        3
4    省政府        4        3        4        4        3        4                                4        3        4
5    肥西        6        5        7        6        5        7        6        5        7           
6    长风        7        7        8        7        7        8        7        7        8           
处理sql语句如下:

 select pro_type, sum(decode(bm_tyoe, '房产', jiage1)) 房产场次, sum(decode(bm_tyoe, '房产', jiage2)) 房产销售价, sum(decode(bm_tyoe, '房产', jiage3)) 房产佣金, sum(decode(bm_tyoe, '汽车', jiage1)) 汽车场次, sum(decode(bm_tyoe, '汽车', jiage2)) 房产销售价, sum(decode(bm_tyoe, '汽车', jiage3)) 汽车佣金, sum(decode(bm_tyoe, '奢侈品', jiage1)) 奢侈品场次, sum(decode(bm_tyoe, '奢侈品', jiage2)) 奢侈品销售价, sum(decode(bm_tyoe, '奢侈品', jiage3)) 奢侈品佣金, sum(decode(bm_tyoe, '贵重首饰', jiage1)) 贵重首饰场次, sum(decode(bm_tyoe, '贵重首饰', jiage2)) 贵重首饰销售价, sum(decode(bm_tyoe, '贵重首饰', jiage3)) 贵重首饰佣金 from tmp_table group by pro_type 
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!