久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

  • <tfoot id='e13Is'></tfoot>

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

        <bdo id='e13Is'></bdo><ul id='e13Is'></ul>
      1. 分解表以按列進行透視(SQL、PYSPARK)

        Break down a table to pivot in columns (SQL,PYSPARK)(分解表以按列進行透視(SQL、PYSPARK))
        <legend id='Rh5YE'><style id='Rh5YE'><dir id='Rh5YE'><q id='Rh5YE'></q></dir></style></legend>

            • <bdo id='Rh5YE'></bdo><ul id='Rh5YE'></ul>

                  <tbody id='Rh5YE'></tbody>
              1. <small id='Rh5YE'></small><noframes id='Rh5YE'>

                • <i id='Rh5YE'><tr id='Rh5YE'><dt id='Rh5YE'><q id='Rh5YE'><span id='Rh5YE'><b id='Rh5YE'><form id='Rh5YE'><ins id='Rh5YE'></ins><ul id='Rh5YE'></ul><sub id='Rh5YE'></sub></form><legend id='Rh5YE'></legend><bdo id='Rh5YE'><pre id='Rh5YE'><center id='Rh5YE'></center></pre></bdo></b><th id='Rh5YE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Rh5YE'><tfoot id='Rh5YE'></tfoot><dl id='Rh5YE'><fieldset id='Rh5YE'></fieldset></dl></div>
                • <tfoot id='Rh5YE'></tfoot>
                  本文介紹了分解表以按列進行透視(SQL、PYSPARK)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 AWS Glue 中的 python3.6 環境在 pyspark 中工作.我有這張桌子:

                  I'm working in an environment pyspark with python3.6 in AWS Glue. I have this table :

                  +----+-----+-----+-----+
                  |year|month|total| loop|
                  +----+-----+-----+-----+
                  |2012|    1|   20|loop1|
                  |2012|    2|   30|loop1|
                  |2012|    1|   10|loop2|
                  |2012|    2|    5|loop2|
                  |2012|    1|   50|loop3|
                  |2012|    2|   60|loop3|
                  +----+-----+-----+-----+
                  

                  我需要得到如下輸出:

                  year    month   total_loop1 total_loop2 total_loop3
                  2012    1         20           10           50
                  2012    2         30           5            60
                  

                  我越接近 SQL 代碼:

                  The closer I have gotten is with the SQL code:

                  select a.year,a.month, a.total,b.total from test a 
                  left join test b
                  on a.loop <> b.loop 
                  and a.year = b.year and a.month=b.month
                  

                  輸出仍然到目前為止:

                  +----+-----+-----+-----+
                  |year|month|total|total|
                  +----+-----+-----+-----+
                  |2012|    1|   20|   10|
                  |2012|    1|   20|   50|
                  |2012|    1|   10|   20|
                  |2012|    1|   10|   50|
                  |2012|    1|   50|   20|
                  |2012|    1|   50|   10|
                  |2012|    2|   30|    5|
                  |2012|    2|   30|   60|
                  |2012|    2|    5|   30|
                  |2012|    2|    5|   60|
                  |2012|    2|   60|   30|
                  |2012|    2|   60|    5|
                  +----+-----+-----+-----+
                  

                  我該怎么做?非常感謝

                  推薦答案

                  表腳本和示例數據

                  CREATE TABLE [TableName](
                      [year] [nvarchar](50) NULL,
                      [month] [int] NULL,
                      [total] [int] NULL,
                      [loop] [nvarchar](50) NULL
                  ) 
                  
                  INSERT [TableName] ([year], [month], [total], [loop]) VALUES (N'2012', 1, 20, N'loop1')
                  INSERT [TableName] ([year], [month], [total], [loop]) VALUES (N'2012', 2, 30, N'loop1')
                  INSERT [TableName] ([year], [month], [total], [loop]) VALUES (N'2012', 1, 10, N'loop2')
                  INSERT [TableName] ([year], [month], [total], [loop]) VALUES (N'2012', 2, 5, N'loop2')
                  INSERT [TableName] ([year], [month], [total], [loop]) VALUES (N'2012', 1, 50, N'loop3')
                  INSERT [TableName] ([year], [month], [total], [loop]) VALUES (N'2012', 2, 60, N'loop3')
                  

                  使用樞軸功能...

                  SELECT * 
                  FROM   TableName
                         PIVOT(Max([total]) 
                              FOR [loop] IN ([loop1], [loop2], [loop3]) ) pvt
                  

                  在線演示:http://www.sqlfiddle.com/#!18/164a4/1/0

                  如果您正在尋找動態解決方案,那么試試這個...(動態樞軸)

                  If you are looking for a dynamic solution, then try this... (Dynamic Pivot)

                  DECLARE @cols AS NVARCHAR(max) = Stuff((SELECT DISTINCT ',' + Quotename([loop])
                           FROM   TableName
                           FOR xml path(''), type).value('.', 'NVARCHAR(MAX)'), 1, 1, ''); 
                  
                  DECLARE @query AS NVARCHAR(max) =  'SELECT * 
                                                      FROM   TableName
                                                             PIVOT(Max([total]) 
                                                                  FOR [loop] IN ('+ @cols +') ) pvt';
                  
                  EXECUTE(@query) 
                  

                  在線演示:http://www.sqlfiddle.com/#!18/164a4/3/0

                  輸出

                  +------+-------+-------+-------+-------+
                  | year | month | loop1 | loop2 | loop3 |
                  +------+-------+-------+-------+-------+
                  | 2012 |     1 |    20 |    10 |    50 |
                  | 2012 |     2 |    30 |     5 |    60 |
                  +------+-------+-------+-------+-------+
                  

                  這篇關于分解表以按列進行透視(SQL、PYSPARK)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)

                    <tbody id='okGL4'></tbody>
                  <i id='okGL4'><tr id='okGL4'><dt id='okGL4'><q id='okGL4'><span id='okGL4'><b id='okGL4'><form id='okGL4'><ins id='okGL4'></ins><ul id='okGL4'></ul><sub id='okGL4'></sub></form><legend id='okGL4'></legend><bdo id='okGL4'><pre id='okGL4'><center id='okGL4'></center></pre></bdo></b><th id='okGL4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='okGL4'><tfoot id='okGL4'></tfoot><dl id='okGL4'><fieldset id='okGL4'></fieldset></dl></div>
                • <tfoot id='okGL4'></tfoot>
                    <bdo id='okGL4'></bdo><ul id='okGL4'></ul>

                        • <small id='okGL4'></small><noframes id='okGL4'>

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

                            主站蜘蛛池模板: 阿v视频在线观看 | 九九免费视频 | 欧美v片 | 午夜一级做a爰片久久毛片 精品综合 | 狠狠色综合网站久久久久久久 | 欧美在线 | av手机在线看 | 久久久一区二区三区 | 中文字幕国产一区 | 欧美性生活视频 | 夜夜操天天操 | 欧美一区二区在线视频 | 久久久久9999 | 99久久视频 | 欧美日韩亚洲系列 | 精品视频导航 | 亚洲视频免费 | 国产激情在线看 | 亚洲人人 | 欧美一区视频 | av香港经典三级级 在线 | 视频在线观看一区二区 | 久艹av | 欧美xxxx色视频在线观看免费 | 亚州精品天堂中文字幕 | 欧美一级二级视频 | 久久成人一区二区三区 | h视频在线免费观看 | 亚洲视频1区 | 亚洲福利电影网 | 午夜视频免费在线观看 | 免费久久久久久 | 免费高潮视频95在线观看网站 | 一区二区三区免费网站 | 爱草在线| 久久成人精品 | 欧美高清一级片 | 国产精品一区二区三区四区 | 国产精品一区二区三区在线播放 | 在线超碰 | 成人av一区 |