久久久久久久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. 分解表以按列進(jìn)行透視(SQL、PYSPARK)

        Break down a table to pivot in columns (SQL,PYSPARK)(分解表以按列進(jìn)行透視(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>
                  本文介紹了分解表以按列進(jìn)行透視(SQL、PYSPARK)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在使用 AWS Glue 中的 python3.6 環(huán)境在 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|
                  +----+-----+-----+-----+
                  

                  我該怎么做?非常感謝

                  推薦答案

                  表腳本和示例數(shù)據(jù)

                  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

                  如果您正在尋找動(dòng)態(tài)解決方案,那么試試這個(gè)...(動(dòng)態(tài)樞軸)

                  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 |
                  +------+-------+-------+-------+-------+
                  

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

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

                  相關(guān)文檔推薦

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

                    <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>

                            主站蜘蛛池模板: 色婷婷av一区二区三区软件 | 中文字幕中文字幕 | 久在草| 精品久久久久久久人人人人传媒 | 午夜伦理影院 | 国产成人精品久久二区二区91 | 国产精品一区二区三区在线播放 | 国产精品亚洲第一 | 最新中文字幕在线 | 超碰97人人人人人蜜桃 | 一区二区精品在线 | 毛片网在线观看 | 久在草 | 欧美久久综合 | 日本精品一区二区在线观看 | 欧美一区二区另类 | 成人精品国产免费网站 | 国产一区二区电影 | a级毛片基地 | 国产黄色精品 | 国产伦一区二区三区四区 | 欧美三区 | 日韩电影免费在线观看中文字幕 | 成人性生交大片免费看中文带字幕 | 高清欧美性猛交xxxx黑人猛交 | 亚洲精彩视频在线观看 | 青青草华人在线视频 | 日本在线一区二区 | 国产专区在线 | 日本精品一区二区三区在线观看视频 | 亚洲欧洲日韩精品 中文字幕 | 成人影 | 日韩精品视频中文字幕 | 狠狠爱一区二区三区 | 粉嫩一区二区三区国产精品 | 国产精品福利视频 | 97国产成人 | 中文字字幕一区二区三区四区五区 | 久久99网 | 黄网站在线播放 | 熟女毛片|