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

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

      1. <small id='mFTe6'></small><noframes id='mFTe6'>

        <legend id='mFTe6'><style id='mFTe6'><dir id='mFTe6'><q id='mFTe6'></q></dir></style></legend>
      2. 獲取每組分組SQL結果的最大值記錄

        Get records with max value for each group of grouped SQL results(獲取每組分組SQL結果的最大值記錄)

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

          <tbody id='idSiq'></tbody>

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

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

                <i id='idSiq'><tr id='idSiq'><dt id='idSiq'><q id='idSiq'><span id='idSiq'><b id='idSiq'><form id='idSiq'><ins id='idSiq'></ins><ul id='idSiq'></ul><sub id='idSiq'></sub></form><legend id='idSiq'></legend><bdo id='idSiq'><pre id='idSiq'><center id='idSiq'></center></pre></bdo></b><th id='idSiq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='idSiq'><tfoot id='idSiq'></tfoot><dl id='idSiq'><fieldset id='idSiq'></fieldset></dl></div>
                  本文介紹了獲取每組分組SQL結果的最大值記錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  如何獲取包含每個分組集最大值的行?

                  How do you get the rows that contain the max value for each grouped set?

                  我在這個問題上看到了一些過于復雜的變體,但沒有一個有好的答案.我試圖把最簡單的例子放在一起:

                  I've seen some overly-complicated variations on this question, and none with a good answer. I've tried to put together the simplest possible example:

                  給定如下表,其中包含人員、組和年齡列,您將如何獲得每個組中最年長的人?(組內平局應給出按字母順序排列的第一個結果)

                  Given a table like that below, with person, group, and age columns, how would you get the oldest person in each group? (A tie within a group should give the first alphabetical result)

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

                  期望的結果集:

                  Shawn | 1     | 42    
                  Laura | 2     | 39  
                  

                  推薦答案

                  在 mysql 中有一個超級簡單的方法來做到這一點:

                  There's a super-simple way to do this in mysql:

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

                  這是可行的,因為在 mysql 中,您可以聚合非 group-by 列,在這種情況下,mysql 只返回 第一 行.解決方案是首先對數據進行排序,以便對于每個組,您想要的行在前,然后按您想要的值的列進行分組.

                  This works because in mysql you're allowed to not aggregate non-group-by columns, in which case mysql just returns the first row. The solution is to first order the data such that for each group the row you want is first, then group by the columns you want the value for.

                  您避免了嘗試查找 max() 等的復雜子查詢,以及當有多個具有相同最大值的行時返回多行的問題(就像其他答案一樣))

                  You avoid complicated subqueries that try to find the max() etc, and also the problems of returning multiple rows when there are more than one with the same maximum value (as the other answers would do)

                  注意:這是一個僅限mysql的解決方案.我知道的所有其他數據庫都會拋出 SQL 語法錯誤,并顯示消息非聚合列未列在 group by 子句中";或類似.由于此解決方案使用未記錄的行為,因此更加謹慎的人可能希望包含一個測試,以斷言如果未來的 MySQL 版本更改此行為,它仍然工作.

                  Note: This is a mysql-only solution. All other databases I know will throw an SQL syntax error with the message "non aggregated columns are not listed in the group by clause" or similar. Because this solution uses undocumented behavior, the more cautious may want to include a test to assert that it remains working should a future version of MySQL change this behavior.

                  從 5.7 版本開始,sql-mode 設置包括 ONLY_FULL_GROUP_BY 默認情況下,因此要使其正常工作,您必須沒有有此選項(編輯服務器的選項文件以刪除此設置).

                  Since version 5.7, the sql-mode setting includes ONLY_FULL_GROUP_BY by default, so to make this work you must not have this option (edit the option file for the server to remove this setting).

                  這篇關于獲取每組分組SQL結果的最大值記錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 數據幀讀取?)

                    • <tfoot id='9Qru5'></tfoot>
                        <bdo id='9Qru5'></bdo><ul id='9Qru5'></ul>
                          <legend id='9Qru5'><style id='9Qru5'><dir id='9Qru5'><q id='9Qru5'></q></dir></style></legend>

                              <tbody id='9Qru5'></tbody>

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

                            <small id='9Qru5'></small><noframes id='9Qru5'>

                          1. 主站蜘蛛池模板: 蜜臀网 | 在线观看中文字幕av | 欧美啊v在线观看 | 日韩在线欧美 | 性高湖久久久久久久久aaaaa | 日韩在线播放第一页 | 中文字幕 在线观看 | 99久久久国产精品 | 夜久久 | 国产精品一区二区三区久久久 | 伊人久麻豆社区 | 亚洲人成人一区二区在线观看 | 国产在线精品一区二区三区 | 日韩中文字幕 | 日韩一区二区三区精品 | 国产精品久久久久婷婷二区次 | 久久免费精品视频 | 精品国产乱码久久久久久闺蜜 | 中文字幕男人的天堂 | 99精品99| www.久久 | 能看的av网站 | 亚洲精品毛片av | 国产精品久久 | 91九色麻豆 | 一区二区三区四区五区在线视频 | 亚洲国产精品一区二区三区 | 欧美日韩综合 | 国产区在线免费观看 | 色在线免费视频 | 亚洲综合日韩精品欧美综合区 | 亚洲国产精品日韩av不卡在线 | 亚洲成在线观看 | 久久99这里只有精品 | 999久久久 | 亚洲国产中文字幕 | 一区二区视频 | 日韩中文字幕网 | 日韩精品免费一区二区在线观看 | 天天躁日日躁狠狠躁2018小说 | 亚洲一区二区三区在线播放 |