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

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

          <bdo id='MyPZM'></bdo><ul id='MyPZM'></ul>
        <tfoot id='MyPZM'></tfoot>

        使用两列透视数据

        Pivoting of data using two columns(使用两列透视数据)

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

                <tfoot id='ehwP3'></tfoot>
                  <tbody id='ehwP3'></tbody>
                  <bdo id='ehwP3'></bdo><ul id='ehwP3'></ul>

                • <legend id='ehwP3'><style id='ehwP3'><dir id='ehwP3'><q id='ehwP3'></q></dir></style></legend>
                  <i id='ehwP3'><tr id='ehwP3'><dt id='ehwP3'><q id='ehwP3'><span id='ehwP3'><b id='ehwP3'><form id='ehwP3'><ins id='ehwP3'></ins><ul id='ehwP3'></ul><sub id='ehwP3'></sub></form><legend id='ehwP3'></legend><bdo id='ehwP3'><pre id='ehwP3'><center id='ehwP3'></center></pre></bdo></b><th id='ehwP3'></th></span></q></dt></tr></i><div id='ehwP3'><tfoot id='ehwP3'></tfoot><dl id='ehwP3'><fieldset id='ehwP3'></fieldset></dl></div>
                  本文介绍了使用两列透视数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有透视格式的数据.它看起来像这样:

                  I have data in pivoted format. It looks like this:

                  -----------------------------------------
                  | user_id |  org  |   position  | lang  |
                  -----------------------------------------
                  |   1001  |   USE |   Boss      | EN    |
                  |   1001  |   USD |   Bossa     | FI    |
                  |   1002  |   GWR |   Dim       | SV    |
                  |   1003  |   GGA |   DCS       | FI    |
                  |   1003  |   GCA |   DDD       | SV    |
                  -----------------------------------------
                  

                  我希望将数据表示为:

                  -------------------------------------------------------------------------------------
                  | user_id | org_fi |  position_fi |   org_en | position_en  | org_sv  | position_sv |
                  -------------------------------------------------------------------------------------
                  |  1001   |   USD  |    Bossa     |   USE    |   Boss       |         |             |
                  |  1002   |        |              |          |              | GWR     |  Dim        |
                  |  1003   |   GGA  |    DCS       |          |              | GCA     |  DDD        |
                  ------------------------------------------------------------------------------------- 
                  

                  我认为需要通过命令连接的数据透视查询.

                  I think that a pivot query with connect by command is needed.

                  这就是我尝试做的:

                  SELECT user_id, 
                      org, 
                      position, 
                      lang, 
                      ROW_NUMBER () OVER (PARTITION BY lang, user_id ORDER BY ROWID) rn
                   FROM source
                  

                  但是,我不知道如何前进.

                  However, I have no idea how to go forward.

                  推荐答案

                  这里提供了一种以您想要的格式获取数据的方法:

                  Here is a way to get the data in the format you want:

                  SELECT user_id, 
                    max(case when lang = 'FI' THEN org ELSE ' ' END) org_fi,
                    max(case when lang = 'FI' THEN position ELSE ' ' END) position_fi,
                    max(case when lang = 'EN' THEN org ELSE ' ' END) org_en,
                    max(case when lang = 'EN' THEN position ELSE ' ' END) position_en,
                    max(case when lang = 'SV' THEN org ELSE ' ' END) org_sv,
                    max(case when lang = 'SV' THEN position ELSE ' ' END) position_sv
                  FROM source
                  group by user_id
                  order by user_id
                  

                  参见SQL Fiddle with Demo

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

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

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

                  <i id='y1VpE'><tr id='y1VpE'><dt id='y1VpE'><q id='y1VpE'><span id='y1VpE'><b id='y1VpE'><form id='y1VpE'><ins id='y1VpE'></ins><ul id='y1VpE'></ul><sub id='y1VpE'></sub></form><legend id='y1VpE'></legend><bdo id='y1VpE'><pre id='y1VpE'><center id='y1VpE'></center></pre></bdo></b><th id='y1VpE'></th></span></q></dt></tr></i><div id='y1VpE'><tfoot id='y1VpE'></tfoot><dl id='y1VpE'><fieldset id='y1VpE'></fieldset></dl></div>
                        <bdo id='y1VpE'></bdo><ul id='y1VpE'></ul>
                          <tbody id='y1VpE'></tbody>
                        <legend id='y1VpE'><style id='y1VpE'><dir id='y1VpE'><q id='y1VpE'></q></dir></style></legend>

                          1. <tfoot id='y1VpE'></tfoot>