久久久久久久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 計(jì)算中位數(shù)的簡(jiǎn)單方法

        Simple way to calculate median with MySQL(用 MySQL 計(jì)算中位數(shù)的簡(jiǎn)單方法)
          <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 計(jì)算中位數(shù)的簡(jiǎn)單方法的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  使用 MySQL 計(jì)算中位數(shù)的最簡(jiǎn)單(希望不會(huì)太慢)方法是什么?我已經(jīng)使用 AVG(x) 來(lái)找到平均值,但我很難找到一種計(jì)算中位數(shù)的簡(jiǎn)單方法.現(xiàn)在,我將所有行返回給 PHP,進(jìn)行排序,然后選擇中間的行,但肯定有一些簡(jiǎn)單的方法可以在單個(gè) MySQL 查詢(xún)中執(zhí)行此操作.

                  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.

                  示例數(shù)據(jù):

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

                  對(duì) val 排序給出 2 2 3 4 7 8 9,所以中位數(shù)應(yīng)該是 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 將包含總行數(shù).這可用于確定中位數(shù),因此不需要第二遍或連接.

                  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(...) 用于在記錄數(shù)為偶數(shù)時(shí)正確生成中位數(shù).推理:

                  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+ 包含一個(gè) MEDIAN 函數(shù)

                  這篇關(guān)于用 MySQL 計(jì)算中位數(shù)的簡(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='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>

                            主站蜘蛛池模板: 成人午夜精品一区二区三区 | 亚洲一区二区三区在线 | 欧美激情欧美激情在线五月 | 欧美精品网站 | 91在线观看免费视频 | 日韩av在线免费 | 国产精品久久久久久婷婷天堂 | 精品国产免费一区二区三区演员表 | 欧美激情在线播放 | 一区二区三区电影在线观看 | 成人免费视频 | 中国美女一级黄色片 | 日本一区二区三区视频在线 | 国产精品久久久久久吹潮 | 亚洲欧美视频一区 | 91在线视频精品 | 91在线一区 | 少妇一级淫片aaaaaaaaa | 久久丝袜 | 欧美一区二区成人 | 婷婷五月色综合 | 久久久国产一区二区三区四区小说 | 精品国产一区二区三区久久久蜜月 | 国产综合久久久久久鬼色 | 欧美日韩一区二区视频在线观看 | 午夜免费网站 | 97超在线视频 | 黄瓜av | 久久美国 | 亚洲精彩视频在线观看 | 特一级黄色毛片 | 99热热99| 福利成人| 二区欧美 | 欧洲精品码一区二区三区免费看 | 亚洲国产精品一区 | 国产一区视频在线 | 成人在线中文字幕 | 成人黄色a | 精品国产一区二区三区久久影院 | 国产探花在线精品一区二区 |