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

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

    <small id='6rXDn'></small><noframes id='6rXDn'>

    <legend id='6rXDn'><style id='6rXDn'><dir id='6rXDn'><q id='6rXDn'></q></dir></style></legend>

      1. MySQL如何填充范圍內缺少的日期?

        MySQL how to fill missing dates in range?(MySQL如何填充范圍內缺少的日期?)
        <legend id='ys8WK'><style id='ys8WK'><dir id='ys8WK'><q id='ys8WK'></q></dir></style></legend>

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

            • <tfoot id='ys8WK'></tfoot>

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

                  <i id='ys8WK'><tr id='ys8WK'><dt id='ys8WK'><q id='ys8WK'><span id='ys8WK'><b id='ys8WK'><form id='ys8WK'><ins id='ys8WK'></ins><ul id='ys8WK'></ul><sub id='ys8WK'></sub></form><legend id='ys8WK'></legend><bdo id='ys8WK'><pre id='ys8WK'><center id='ys8WK'></center></pre></bdo></b><th id='ys8WK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ys8WK'><tfoot id='ys8WK'></tfoot><dl id='ys8WK'><fieldset id='ys8WK'></fieldset></dl></div>
                    <tbody id='ys8WK'></tbody>
                1. 本文介紹了MySQL如何填充范圍內缺少的日期?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個包含 2 列、日期和分數的表格.它最多有 30 個條目,對于過去 30 天的每一天.

                  I have a table with 2 columns, date and score. It has at most 30 entries, for each of the last 30 days one.

                  date      score
                  -----------------
                  1.8.2010  19
                  2.8.2010  21
                  4.8.2010  14
                  7.8.2010  10
                  10.8.2010 14
                  

                  我的問題是缺少某些日期 - 我想看看:

                  My problem is that some dates are missing - I want to see:

                  date      score
                  -----------------
                  1.8.2010  19
                  2.8.2010  21
                  3.8.2010  0
                  4.8.2010  14
                  5.8.2010  0
                  6.8.2010  0
                  7.8.2010  10
                  ...
                  

                  我需要從單個查詢中得到:19,21,9,14,0,0,10,0,0,14...這意味著缺少的日期用 0 填充.

                  What I need from the single query is to get: 19,21,9,14,0,0,10,0,0,14... That means that the missing dates are filled with 0.

                  我知道如何獲取所有值并使用服務器端語言迭代日期并遺漏空格.但這是否可以在 mysql 中進行,以便我按日期對結果進行排序并獲取丟失的部分.

                  I know how to get all the values and in server side language iterating through dates and missing the blanks. But is this possible to do in mysql, so that I sort the result by date and get the missing pieces.

                  在這個表中還有一個名為 UserID 的列,所以我有 30.000 個用戶,其中一些在這個表中有分數.如果日期<,我每天都會刪除日期30 天前,因為我需要每個用戶最近 30 天的分數.原因是我正在制作過去 30 天的用戶活動圖表,并繪制圖表我需要用逗號分隔的 30 個值.所以我可以說在查詢中讓我獲得 USERID=10203 活動,查詢將獲得 30 個分數,過去 30 天的每一天都有一個分數.我希望我現在更清楚了.

                  In this table there is another column named UserID, so I have 30.000 users and some of them have the score in this table. I delete the dates every day if date < 30 days ago because I need last 30 days score for each user. The reason is I am making a graph of the user activity over the last 30 days and to plot a chart I need the 30 values separated by comma. So I can say in query get me the USERID=10203 activity and the query would get me the 30 scores, one for each of the last 30 days. I hope I am more clear now.

                  推薦答案

                  MySQL 沒有遞歸功能,因此您只能使用 NUMBERS 表技巧 -

                  MySQL doesn't have recursive functionality, so you're left with using the NUMBERS table trick -

                  1. 創建一個只保存遞增數字的表 - 使用 auto_increment 很容易做到:

                  1. Create a table that only holds incrementing numbers - easy to do using an auto_increment:

                  DROP TABLE IF EXISTS `example`.`numbers`;
                  CREATE TABLE  `example`.`numbers` (
                    `id` int(10) unsigned NOT NULL auto_increment,
                     PRIMARY KEY  (`id`)
                  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
                  

                2. 使用以下方法填充表格:

                3. Populate the table using:

                  INSERT INTO `example`.`numbers`
                    ( `id` )
                  VALUES
                    ( NULL )
                  

                  ...根據您的需要獲取盡可能多的值.

                  ...for as many values as you need.

                  使用DATE_ADD 構建日期列表,根據 NUMBERS.id 值增加天數.用您各自的開始和結束日期替換2010-06-06"和2010-06-14"(但使用相同的格式,YYYY-MM-DD)-

                  Use DATE_ADD to construct a list of dates, increasing the days based on the NUMBERS.id value. Replace "2010-06-06" and "2010-06-14" with your respective start and end dates (but use the same format, YYYY-MM-DD) -

                  SELECT `x`.*
                    FROM (SELECT DATE_ADD('2010-06-06', INTERVAL `n`.`id` - 1 DAY)
                            FROM `numbers` `n`
                           WHERE DATE_ADD('2010-06-06', INTERVAL `n`.`id` -1 DAY) <= '2010-06-14' ) x
                  

                4. LEFT JOIN 根據時間部分加入您的數據表:

                5. LEFT JOIN onto your table of data based on the time portion:

                     SELECT `x`.`ts` AS `timestamp`,
                            COALESCE(`y`.`score`, 0) AS `cnt`
                       FROM (SELECT DATE_FORMAT(DATE_ADD('2010-06-06', INTERVAL `n`.`id` - 1 DAY), '%m/%d/%Y') AS `ts`
                               FROM `numbers` `n`
                              WHERE DATE_ADD('2010-06-06', INTERVAL `n`.`id` - 1 DAY) <= '2010-06-14') x
                  LEFT JOIN TABLE `y` ON STR_TO_DATE(`y`.`date`, '%d.%m.%Y') = `x`.`ts`
                  

                6. 如果要保持日期格式,請使用 DATE_FORMAT 函數:

                  If you want to maintain the date format, use the DATE_FORMAT function:

                  DATE_FORMAT(`x`.`ts`, '%d.%m.%Y') AS `timestamp`
                  

                  這篇關于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 數據幀讀取?)

                    <bdo id='tB7lM'></bdo><ul id='tB7lM'></ul>
                    <legend id='tB7lM'><style id='tB7lM'><dir id='tB7lM'><q id='tB7lM'></q></dir></style></legend>

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

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

                          2. 主站蜘蛛池模板: 91精品久久久久久久久中文字幕 | 九九热免费看 | www.99热| 伊色综合久久之综合久久 | 久久精品视频在线免费观看 | 欧美黄色大片在线观看 | 亚洲一区免费 | 亚洲一区二区av在线 | 国产亚洲成av人在线观看导航 | 国产欧美一区二区在线观看 | 精品国产一区探花在线观看 | 亚洲欧美日韩在线 | xx性欧美肥妇精品久久久久久 | 国产黄色一级片 | 免费在线国产视频 | 成人在线视频免费观看 | 欧美大片黄| 欧美精品一区二区三区在线播放 | 欧美三区视频 | www.天天干.com | 久久久无码精品亚洲日韩按摩 | 免费一区| 精品国产第一区二区三区 | 日日骚视频 | 国产综合精品一区二区三区 | 成人在线观看免费爱爱 | 午夜专区 | 欧美精品v国产精品v日韩精品 | 97色在线观看免费视频 | 亚洲乱码一区二区三区在线观看 | 久久毛片| 欧美精品在线观看 | 伊人伊人伊人 | 久久精品国产亚洲a | 亚洲综合色视频在线观看 | 国产福利在线播放 | 精品国产一二三区 | 亚洲精品1区 | 国产精品国产成人国产三级 | 国产99免费 | 韩日av片|