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

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

Jun 07, 2016 pm 05:40 PM
decode oracle use data Convert conduct

如何将以下数据格式的数据转换为初始化格式如下: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 
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How long will Oracle database logs be kept? How long will Oracle database logs be kept? May 10, 2024 am 03:27 AM

How long will Oracle database logs be kept?

The order of the oracle database startup steps is The order of the oracle database startup steps is May 10, 2024 am 01:48 AM

The order of the oracle database startup steps is

Oracle database server hardware configuration requirements Oracle database server hardware configuration requirements May 10, 2024 am 04:00 AM

Oracle database server hardware configuration requirements

How to see the number of occurrences of a certain character in Oracle How to see the number of occurrences of a certain character in Oracle May 09, 2024 pm 09:33 PM

How to see the number of occurrences of a certain character in Oracle

How much memory does oracle require? How much memory does oracle require? May 10, 2024 am 04:12 AM

How much memory does oracle require?

How much memory is needed to use oracle database How much memory is needed to use oracle database May 10, 2024 am 03:42 AM

How much memory is needed to use oracle database

Oracle scheduled tasks execute the creation step once a day Oracle scheduled tasks execute the creation step once a day May 10, 2024 am 03:03 AM

Oracle scheduled tasks execute the creation step once a day

70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI 70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI Jun 13, 2024 pm 03:47 PM

70B model generates 1,000 tokens in seconds, code rewriting surpasses GPT-4o, from the Cursor team, a code artifact invested by OpenAI

See all articles