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

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

        <tfoot id='gqWxG'></tfoot>
      1. <legend id='gqWxG'><style id='gqWxG'><dir id='gqWxG'><q id='gqWxG'></q></dir></style></legend>
          <bdo id='gqWxG'></bdo><ul id='gqWxG'></ul>
      2. <i id='gqWxG'><tr id='gqWxG'><dt id='gqWxG'><q id='gqWxG'><span id='gqWxG'><b id='gqWxG'><form id='gqWxG'><ins id='gqWxG'></ins><ul id='gqWxG'></ul><sub id='gqWxG'></sub></form><legend id='gqWxG'></legend><bdo id='gqWxG'><pre id='gqWxG'><center id='gqWxG'></center></pre></bdo></b><th id='gqWxG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gqWxG'><tfoot id='gqWxG'></tfoot><dl id='gqWxG'><fieldset id='gqWxG'></fieldset></dl></div>
      3. 獲取每組分組結(jié)果的前 n 條記錄

        Get top n records for each group of grouped results(獲取每組分組結(jié)果的前 n 條記錄)

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

            1. <legend id='IHlPF'><style id='IHlPF'><dir id='IHlPF'><q id='IHlPF'></q></dir></style></legend>

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

              1. <i id='IHlPF'><tr id='IHlPF'><dt id='IHlPF'><q id='IHlPF'><span id='IHlPF'><b id='IHlPF'><form id='IHlPF'><ins id='IHlPF'></ins><ul id='IHlPF'></ul><sub id='IHlPF'></sub></form><legend id='IHlPF'></legend><bdo id='IHlPF'><pre id='IHlPF'><center id='IHlPF'></center></pre></bdo></b><th id='IHlPF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IHlPF'><tfoot id='IHlPF'></tfoot><dl id='IHlPF'><fieldset id='IHlPF'></fieldset></dl></div>
                • 本文介紹了獲取每組分組結(jié)果的前 n 條記錄的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  以下是最簡(jiǎn)單的示例,但任何解決方案都應(yīng)該能夠擴(kuò)展到需要多少 n 個(gè)頂級(jí)結(jié)果:

                  給定如下表,其中包含人、組和年齡列,您將如何獲得每個(gè)組中最年長(zhǎng)的 2 個(gè)人?(組內(nèi)的關(guān)系不應(yīng)產(chǎn)生更多結(jié)果,而是給出按字母順序排列的前 2 個(gè))

                  <前>+--------+-------+-----+|人 |集團(tuán) |年齡 |+--------+-------+-----+|鮑勃 |1 |32 ||吉爾 |1 |34 ||肖恩 |1 |42 ||杰克 |2 |29 ||保羅 |2 |36 ||勞拉 |2 |39 |+--------+-------+-----+

                  期望的結(jié)果集:

                  <前>+--------+-------+-----+|肖恩 |1 |42 ||吉爾 |1 |34 ||勞拉 |2 |39 ||保羅 |2 |36 |+--------+-------+-----+

                  <小時(shí)>

                  注意:這個(gè)問(wèn)題建立在上一個(gè)問(wèn)題的基礎(chǔ)上 - 獲取每組分組的最大值的記錄SQL 結(jié)果 - 用于從每個(gè)組中獲得一個(gè)頂行,并且從 @Bohemian 那里收到了一個(gè)很好的 MySQL 特定答案:

                  選擇 *from (select * from mytable order by `Group`, Age desc, Person) x按組"分組

                  希望能夠以此為基礎(chǔ),盡管我不知道如何.

                  解決方案

                  這是一種方法,使用 UNION ALL(參見(jiàn) SQL Fiddle with Demo).這適用于兩個(gè)組,如果您有兩個(gè)以上的組,則需要指定 group 編號(hào)并為每個(gè) group 添加查詢:

                  <代碼>(選擇 *來(lái)自 mytable其中`組`= 1按年齡排序限制 2)聯(lián)合所有(選擇 *來(lái)自 mytable其中`組`= 2按年齡排序限制 2)

                  有多種方法可以做到這一點(diǎn),請(qǐng)參閱本文以確定適合您情況的最佳路線:

                  http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/

                  這也可能對(duì)您有用,它為每條記錄生成一個(gè)行號(hào).使用上面鏈接中的示例,這將僅返回行數(shù)小于或等于 2 的那些記錄:

                  選擇人物,`group`,年齡從(選擇人、組"、年齡、(@num:=if(@group = `group`, @num +1, if(@group := `group`, 1, 1))) row_number從測(cè)試 t交叉連接(選擇@num:=0,@group:=null)c按組"、年齡、人排序) 作為 x其中 x.row_number <= 2;

                  參見(jiàn)演示

                  The following is the simplest possible example, though any solution should be able to scale to however many n top results are needed:

                  Given a table like that below, with person, group, and age columns, how would you get the 2 oldest people in each group? (Ties within groups should not yield more results, but give the first 2 in alphabetical order)

                  +--------+-------+-----+
                  | Person | Group | Age |
                  +--------+-------+-----+
                  | Bob    | 1     | 32  |
                  | Jill   | 1     | 34  |
                  | Shawn  | 1     | 42  |
                  | Jake   | 2     | 29  |
                  | Paul   | 2     | 36  |
                  | Laura  | 2     | 39  |
                  +--------+-------+-----+
                  

                  Desired result set:

                  +--------+-------+-----+
                  | Shawn  | 1     | 42  |
                  | Jill   | 1     | 34  |
                  | Laura  | 2     | 39  |
                  | Paul   | 2     | 36  |
                  +--------+-------+-----+
                  


                  NOTE: This question builds on a previous one- Get records with max value for each group of grouped SQL results - for getting a single top row from each group, and which received a great MySQL-specific answer from @Bohemian:

                  select * 
                  from (select * from mytable order by `Group`, Age desc, Person) x
                  group by `Group`
                  

                  Would love to be able to build off this, though I don't see how.

                  解決方案

                  Here is one way to do this, using UNION ALL (See SQL Fiddle with Demo). This works with two groups, if you have more than two groups, then you would need to specify the group number and add queries for each group:

                  (
                    select *
                    from mytable 
                    where `group` = 1
                    order by age desc
                    LIMIT 2
                  )
                  UNION ALL
                  (
                    select *
                    from mytable 
                    where `group` = 2
                    order by age desc
                    LIMIT 2
                  )
                  

                  There are a variety of ways to do this, see this article to determine the best route for your situation:

                  http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/

                  Edit:

                  This might work for you too, it generates a row number for each record. Using an example from the link above this will return only those records with a row number of less than or equal to 2:

                  select person, `group`, age
                  from 
                  (
                     select person, `group`, age,
                        (@num:=if(@group = `group`, @num +1, if(@group := `group`, 1, 1))) row_number 
                    from test t
                    CROSS JOIN (select @num:=0, @group:=null) c
                    order by `Group`, Age desc, person
                  ) as x 
                  where x.row_number <= 2;
                  

                  See Demo

                  這篇關(guān)于獲取每組分組結(jié)果的前 n 條記錄的文章就介紹到這了,希望我們推薦的答案對(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='LUbNA'></tbody>

                    • <bdo id='LUbNA'></bdo><ul id='LUbNA'></ul>
                      1. <small id='LUbNA'></small><noframes id='LUbNA'>

                        <tfoot id='LUbNA'></tfoot>

                          <legend id='LUbNA'><style id='LUbNA'><dir id='LUbNA'><q id='LUbNA'></q></dir></style></legend>
                          • <i id='LUbNA'><tr id='LUbNA'><dt id='LUbNA'><q id='LUbNA'><span id='LUbNA'><b id='LUbNA'><form id='LUbNA'><ins id='LUbNA'></ins><ul id='LUbNA'></ul><sub id='LUbNA'></sub></form><legend id='LUbNA'></legend><bdo id='LUbNA'><pre id='LUbNA'><center id='LUbNA'></center></pre></bdo></b><th id='LUbNA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LUbNA'><tfoot id='LUbNA'></tfoot><dl id='LUbNA'><fieldset id='LUbNA'></fieldset></dl></div>
                            主站蜘蛛池模板: 久久伊人av| 色婷婷在线视频 | 麻豆精品一区 | 91亚洲国产 | 亚洲精品社区 | avxxxxx | 午夜成人影视 | 国产精品一级 | 色av吧 | 精品少妇一区二区三区免费观 | 国产美女视频 | 啪啪毛片 | 精品视频在线观看免费 | 免费黄色一级 | 影音先锋在线观看视频 | 日本一级一片免费视频 | 日韩av在线网址 | 天天射天天舔 | 精品日韩一区二区三区 | 日本不卡在线 | 不卡av网站 | 色片在线观看 | 日日干夜夜爽 | 日韩精品一区二区三区免费视频 | 啪啪免费网站 | 在线观看欧美日韩 | 视频一区二区三区在线观看 | 天天爽夜夜操 | 97精品超碰一区二区三区 | 日本国产精品 | 亚洲欧洲视频 | 97人人草| 高潮一区二区三区乱码 | 黄色一级免费视频 | 欧美日韩在线免费 | 欧美69式性猛交 | 国产精品一区二区在线播放 | 久久天天躁狠狠躁夜夜躁2014 | 国产精品久久久一区二区三区 | 久久av影院 | 免费a视频|