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

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

    <tfoot id='bLgCP'></tfoot>

      1. <legend id='bLgCP'><style id='bLgCP'><dir id='bLgCP'><q id='bLgCP'></q></dir></style></legend>
          <bdo id='bLgCP'></bdo><ul id='bLgCP'></ul>

        用 MySQL 計算中位數的簡單方法

        Simple way to calculate median with MySQL(用 MySQL 計算中位數的簡單方法)
          <legend id='Cu2qH'><style id='Cu2qH'><dir id='Cu2qH'><q id='Cu2qH'></q></dir></style></legend>

              • <bdo id='Cu2qH'></bdo><ul id='Cu2qH'></ul>
              • <small id='Cu2qH'></small><noframes id='Cu2qH'>

                  <tbody id='Cu2qH'></tbody>
                <tfoot id='Cu2qH'></tfoot>
                <i id='Cu2qH'><tr id='Cu2qH'><dt id='Cu2qH'><q id='Cu2qH'><span id='Cu2qH'><b id='Cu2qH'><form id='Cu2qH'><ins id='Cu2qH'></ins><ul id='Cu2qH'></ul><sub id='Cu2qH'></sub></form><legend id='Cu2qH'></legend><bdo id='Cu2qH'><pre id='Cu2qH'><center id='Cu2qH'></center></pre></bdo></b><th id='Cu2qH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Cu2qH'><tfoot id='Cu2qH'></tfoot><dl id='Cu2qH'><fieldset id='Cu2qH'></fieldset></dl></div>
                  本文介紹了用 MySQL 計算中位數的簡單方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  使用 MySQL 計算中位數的最簡單(希望不會太慢)方法是什么?我已經使用 AVG(x) 來找到平均值,但我很難找到一種計算中位數的簡單方法.現在,我將所有行返回給 PHP,進行排序,然后選擇中間的行,但肯定有一些簡單的方法可以在單個 MySQL 查詢中執行此操作.

                  What's the simplest (and hopefully not too slow) way to calculate the median with MySQL? I've used AVG(x) for finding the mean, but I'm having a hard time finding a simple way of calculating the median. For now, I'm returning all the rows to PHP, doing a sort, and then picking the middle row, but surely there must be some simple way of doing it in a single MySQL query.

                  示例數據:

                  id | val
                  --------
                   1    4
                   2    7
                   3    2
                   4    2
                   5    9
                   6    8
                   7    3
                  

                  val 排序給出 2 2 3 4 7 8 9,所以中位數應該是 4,而 SELECT AVG(val) which == 5.

                  Sorting on val gives 2 2 3 4 7 8 9, so the median should be 4, versus SELECT AVG(val) which == 5.

                  推薦答案

                  在 MariaDB/MySQL 中:

                  In MariaDB / MySQL:

                  SELECT AVG(dd.val) as median_val
                  FROM (
                  SELECT d.val, @rownum:=@rownum+1 as `row_number`, @total_rows:=@rownum
                    FROM data d, (SELECT @rownum:=0) r
                    WHERE d.val is NOT NULL
                    -- put some where clause here
                    ORDER BY d.val
                  ) as dd
                  WHERE dd.row_number IN ( FLOOR((@total_rows+1)/2), FLOOR((@total_rows+2)/2) );
                  

                  Steve Cohen 指出,在第一遍之后,@rownum 將包含總行數.這可用于確定中位數,因此不需要第二遍或連接.

                  Steve Cohen points out, that after the first pass, @rownum will contain the total number of rows. This can be used to determine the median, so no second pass or join is needed.

                  還有 AVG(dd.val)dd.row_number IN(...) 用于在記錄數為偶數時正確生成中位數.推理:

                  Also AVG(dd.val) and dd.row_number IN(...) is used to correctly produce a median when there are an even number of records. Reasoning:

                  SELECT FLOOR((3+1)/2),FLOOR((3+2)/2); -- when total_rows is 3, avg rows 2 and 2
                  SELECT FLOOR((4+1)/2),FLOOR((4+2)/2); -- when total_rows is 4, avg rows 2 and 3
                  

                  最后,MariaDB 10.3.3+ 包含一個 MEDIAN 函數

                  這篇關于用 MySQL 計算中位數的簡單方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='OTdCw'></tbody>

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

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

                            主站蜘蛛池模板: 欧美日韩在线免费观看 | 一级黄色在线观看 | 欧美日韩综合 | 久操久操 | 欧美精品系列 | 玖玖在线观看 | 国产做爰视频免费播放 | 蜜臀久久99精品久久久久久宅男 | 亚洲综合一区二区 | 日韩av在线看 | 久久av网站 | 欧美日韩激情 | 精品久久一区二区三区 | 欧美精产国品一二三区 | 麻豆国产91在线播放 | 日韩一级在线观看 | 又色又爽又黄18网站 | 精品久久一区二区 | 黄色免费毛片 | 午夜精品视频在线观看 | 九色91popny蝌蚪新疆 | 亚洲精品91天天久久人人 | 欧美日韩亚洲一区二区 | av免费网| 99久久久国产精品免费蜜臀 | 国产精品一区二区久久 | 少妇搡bbbb搡bbb搡毛茸茸 | 免费一级黄色片 | 51av视频| 日本国产视频 | 日韩特级毛片 | 午夜在线视频 | 亚洲精品午夜精品 | 韩国精品一区 | 亚洲影院一区 | 激情综合色| 狠狠操网 | 国产成人精品免费视频 | 欧美黄色片网站 | 国产精品手机在线 | 91国内在线 |