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

    <bdo id='D6VL7'></bdo><ul id='D6VL7'></ul>

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

    <legend id='D6VL7'><style id='D6VL7'><dir id='D6VL7'><q id='D6VL7'></q></dir></style></legend>
  1. <small id='D6VL7'></small><noframes id='D6VL7'>

  2. <tfoot id='D6VL7'></tfoot>

    1. 模擬 MySQL 中的滯后函數

      Simulate lag function in MySQL(模擬 MySQL 中的滯后函數)

          <tbody id='8mzZh'></tbody>

          <bdo id='8mzZh'></bdo><ul id='8mzZh'></ul>
            <tfoot id='8mzZh'></tfoot>

                <small id='8mzZh'></small><noframes id='8mzZh'>

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

                問題描述

                | time                | company | quote |
                +---------------------+---------+-------+
                | 0000-00-00 00:00:00 | GOOGLE  |    40 |
                | 2012-07-02 21:28:05 | GOOGLE  |    60 |
                | 2012-07-02 21:28:51 | SAP     |    60 |
                | 2012-07-02 21:29:05 | SAP     |    20 |
                

                我如何在 MySQL 中對這個表做滯后以打印引號中的差異,例如:

                How do I do a lag on this table in MySQL to print the difference in quotes, for example:

                GOOGLE | 20
                SAP    | 40  
                

                推薦答案

                這是我最喜歡的 MySQL hack.

                This is my favorite MySQL hack.

                這是模擬滯后函數的方式:

                This is how you emulate the lag function:

                SET @quot=-1;
                select time,company,@quot lag_quote, @quot:=quote curr_quote
                  from stocks order by company,time;
                

                • lag_quote 保存前一行引用的值.對于第一行,@quot 是 -1.
                • curr_quote 保存當前行的引用值.
                  • lag_quote holds the value of previous row's quote. For the first row @quot is -1.
                  • curr_quote holds the value of current row's quote.
                  • 注意事項:

                    1. order by 子句在這里很重要,就像在常規中一樣窗函數.
                    2. 您可能還想對 company 使用滯后,以確保您計算的是同一 company 的引號中的差異.
                    3. 你也可以用同樣的方式實現行計數器@cnt:=@cnt+1
                    1. order by clause is important here just like it is in a regular window function.
                    2. You might also want to use lag for company just to be sure that you are computing difference in quotes of the same company.
                    3. You can also implement row counters in the same way @cnt:=@cnt+1

                    與使用聚合函數、存儲過程或在應用服務器中處理數據等其他一些方法相比,這種方案的優點是計算量非常小.

                    The nice thing about this scheme is that is computationally very lean compared to some other approaches like using aggregate functions, stored procedures or processing data in application server.

                    現在來解決以您提到的格式獲取結果的問題:

                    Now coming to your question of getting result in the format you mentioned:

                    SET @quot=0,@latest=0,company='';
                    select B.* from (
                    select A.time,A.change,IF(@comp<>A.company,1,0) as LATEST,@comp:=A.company as company from (
                    select time,company,quote-@quot as change, @quot:=quote curr_quote
                    from stocks order by company,time) A
                    order by company,time desc) B where B.LATEST=1;
                    

                    嵌套是不相關的,所以沒有它看起來(語法上)那么糟糕(計算上):)

                    The nesting is not co-related so not as bad (computationally) as it looks (syntactically) :)

                    如果您需要任何幫助,請告訴我.

                    Let me know if you need any help with this.

                    這篇關于模擬 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='PDt9g'></tbody>
                    <i id='PDt9g'><tr id='PDt9g'><dt id='PDt9g'><q id='PDt9g'><span id='PDt9g'><b id='PDt9g'><form id='PDt9g'><ins id='PDt9g'></ins><ul id='PDt9g'></ul><sub id='PDt9g'></sub></form><legend id='PDt9g'></legend><bdo id='PDt9g'><pre id='PDt9g'><center id='PDt9g'></center></pre></bdo></b><th id='PDt9g'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PDt9g'><tfoot id='PDt9g'></tfoot><dl id='PDt9g'><fieldset id='PDt9g'></fieldset></dl></div>
                    <legend id='PDt9g'><style id='PDt9g'><dir id='PDt9g'><q id='PDt9g'></q></dir></style></legend>

                      <bdo id='PDt9g'></bdo><ul id='PDt9g'></ul>
                    • <tfoot id='PDt9g'></tfoot>

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

                        • 主站蜘蛛池模板: 手机av免费在线 | 在线中文字幕av | 日韩中文字幕视频 | 性精品 | 久久久91精品国产一区二区三区 | 欧美成人a∨高清免费观看 91伊人 | 亚洲精品亚洲人成人网 | 中文字幕一区二区三区四区 | 国产精品日韩欧美一区二区三区 | 国产毛片久久久 | 超碰人人艹| 国产精品免费一区二区三区四区 | 草草草久久久 | 久久99精品久久久久婷婷 | 久色视频在线 | 国产高清视频 | 精品国产18久久久久久二百 | 国产色爽 | 激情五月婷婷 | 亚洲欧美在线观看 | 岛国av免费在线观看 | 99热国产免费 | 欧洲妇女成人淫片aaa视频 | 国产精品久久久久久久久久妞妞 | 成人免费看片 | 精品一区视频 | 免费在线精品视频 | 99精品视频一区二区三区 | 成人精品一区 | 久久亚洲国产精品 | 亚洲美女在线视频 | 国产日韩精品在线 | 国产欧美一区二区三区在线看 | 欧美一二三 | 国产精品一区在线观看 | 国产精品一区二区精品 | 免费视频一区二区 | 久久久久久久久久久久久久国产 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 特级特黄特色的免费大片 | 精品美女视频在线观看免费软件 |