<legend id='VJb6C'><style id='VJb6C'><dir id='VJb6C'><q id='VJb6C'></q></dir></style></legend>
      <bdo id='VJb6C'></bdo><ul id='VJb6C'></ul>

    <small id='VJb6C'></small><noframes id='VJb6C'>

    <tfoot id='VJb6C'></tfoot>
  1. <i id='VJb6C'><tr id='VJb6C'><dt id='VJb6C'><q id='VJb6C'><span id='VJb6C'><b id='VJb6C'><form id='VJb6C'><ins id='VJb6C'></ins><ul id='VJb6C'></ul><sub id='VJb6C'></sub></form><legend id='VJb6C'></legend><bdo id='VJb6C'><pre id='VJb6C'><center id='VJb6C'></center></pre></bdo></b><th id='VJb6C'></th></span></q></dt></tr></i><div id='VJb6C'><tfoot id='VJb6C'></tfoot><dl id='VJb6C'><fieldset id='VJb6C'></fieldset></dl></div>

    1. Oracle SQL 数据透视查询

      Oracle SQL pivot query(Oracle SQL 数据透视查询)

      1. <tfoot id='yirP8'></tfoot>
          • <i id='yirP8'><tr id='yirP8'><dt id='yirP8'><q id='yirP8'><span id='yirP8'><b id='yirP8'><form id='yirP8'><ins id='yirP8'></ins><ul id='yirP8'></ul><sub id='yirP8'></sub></form><legend id='yirP8'></legend><bdo id='yirP8'><pre id='yirP8'><center id='yirP8'></center></pre></bdo></b><th id='yirP8'></th></span></q></dt></tr></i><div id='yirP8'><tfoot id='yirP8'></tfoot><dl id='yirP8'><fieldset id='yirP8'></fieldset></dl></div>

              <legend id='yirP8'><style id='yirP8'><dir id='yirP8'><q id='yirP8'></q></dir></style></legend>

              <small id='yirP8'></small><noframes id='yirP8'>

                <tbody id='yirP8'></tbody>
              • <bdo id='yirP8'></bdo><ul id='yirP8'></ul>
                本文介绍了Oracle SQL 数据透视查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在表格中有数据,如下所示:

                I have data in a table as seen below:

                MONTH VALUE
                
                1     100
                2     200
                3     300
                4     400
                5     500
                6     600
                

                我想写一个 SQL 查询,结果如下:

                I want to write a SQL query so that result is given as below:

                MONTH_JAN MONTH_FEB MONTH_MAR MONTH_APR MONTH_MAY MONTH_JUN
                100       200       300       400       500       600
                

                推荐答案

                Oracle 9i+ 支持:

                SELECT SUM(CASE WHEN t.month = 1 THEN t.value ELSE 0 END) AS JAN,
                       SUM(CASE WHEN t.month = 2 THEN t.value ELSE 0 END) AS FEB,
                       SUM(CASE WHEN t.month = 3 THEN t.value ELSE 0 END) AS MAR,
                       SUM(CASE WHEN t.month = 4 THEN t.value ELSE 0 END) AS APR,
                       SUM(CASE WHEN t.month = 5 THEN t.value ELSE 0 END) AS MAY,
                       SUM(CASE WHEN t.month = 6 THEN t.value ELSE 0 END) AS JUN
                  FROM YOUR_TABLE t
                

                你只列出了两列——像这样的东西可能应该按年份分组.

                You only list two columns -- something like this should probably be grouped by year.

                有 ANSI PIVOT(和 UNPIVOT)语法,但 Oracle 直到 11g 才支持它.在 9i 之前,您必须用 Oracle 特定的 DECODE 替换 CASE 语句.

                There is ANSI PIVOT (and UNPIVOT) syntax, but Oracle didn't support it until 11g. Prior to 9i, you'd have to replace the CASE statements with Oracle specific DECODE.

                这篇关于Oracle SQL 数据透视查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                How ROWNUM works in pagination query?(ROWNUM 如何在分页查询中工作?)
                  <bdo id='jxFzo'></bdo><ul id='jxFzo'></ul>

                    <small id='jxFzo'></small><noframes id='jxFzo'>

                      • <legend id='jxFzo'><style id='jxFzo'><dir id='jxFzo'><q id='jxFzo'></q></dir></style></legend>

                        1. <i id='jxFzo'><tr id='jxFzo'><dt id='jxFzo'><q id='jxFzo'><span id='jxFzo'><b id='jxFzo'><form id='jxFzo'><ins id='jxFzo'></ins><ul id='jxFzo'></ul><sub id='jxFzo'></sub></form><legend id='jxFzo'></legend><bdo id='jxFzo'><pre id='jxFzo'><center id='jxFzo'></center></pre></bdo></b><th id='jxFzo'></th></span></q></dt></tr></i><div id='jxFzo'><tfoot id='jxFzo'></tfoot><dl id='jxFzo'><fieldset id='jxFzo'></fieldset></dl></div>

                            <tbody id='jxFzo'></tbody>
                          <tfoot id='jxFzo'></tfoot>