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

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

        • <bdo id='wMXTP'></bdo><ul id='wMXTP'></ul>
      1. 如何在 MySQL 中進行遞歸 SELECT 查詢?

        How to do the Recursive SELECT query in MySQL?(如何在 MySQL 中進行遞歸 SELECT 查詢?)
        <i id='zhEiV'><tr id='zhEiV'><dt id='zhEiV'><q id='zhEiV'><span id='zhEiV'><b id='zhEiV'><form id='zhEiV'><ins id='zhEiV'></ins><ul id='zhEiV'></ul><sub id='zhEiV'></sub></form><legend id='zhEiV'></legend><bdo id='zhEiV'><pre id='zhEiV'><center id='zhEiV'></center></pre></bdo></b><th id='zhEiV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zhEiV'><tfoot id='zhEiV'></tfoot><dl id='zhEiV'><fieldset id='zhEiV'></fieldset></dl></div>
        • <bdo id='zhEiV'></bdo><ul id='zhEiV'></ul>
            • <small id='zhEiV'></small><noframes id='zhEiV'>

                <legend id='zhEiV'><style id='zhEiV'><dir id='zhEiV'><q id='zhEiV'></q></dir></style></legend><tfoot id='zhEiV'></tfoot>

                  <tbody id='zhEiV'></tbody>

                  本文介紹了如何在 MySQL 中進行遞歸 SELECT 查詢?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我得到了下表:

                  col1 | col2 | col3
                  -----+------+-------
                  1    | a    | 5
                  5    | d    | 3
                  3    | k    | 7
                  6    | o    | 2
                  2    | 0    | 8
                  

                  如果用戶搜索1",程序將查看具有1"的 col1 然后它會在 col3 中得到一個值5",然后程序會繼續在col1中搜索5",在col3中會得到3",以此類推.所以它會打印出來:

                  If a user searches for "1", the program will look at the col1 that has "1" then it will get a value in col3 "5", then the program will continue to search for "5" in col1 and it will get "3" in col3, and so on. So it will print out:

                  1   | a   | 5
                  5   | d   | 3
                  3   | k   | 7
                  

                  如果用戶搜索6",它會打印出來:

                  If a user search for "6", it will print out:

                  6   | o   | 2
                  2   | 0   | 8
                  

                  如何構建 SELECT 查詢來做到這一點?

                  How to build a SELECT query to do that?

                  推薦答案

                  編輯

                  @leftclickben 提到的解決方案也是有效的.我們也可以使用存儲過程.

                  Solution mentioned by @leftclickben is also effective. We can also use a stored procedure for the same.

                  CREATE PROCEDURE get_tree(IN id int)
                   BEGIN
                   DECLARE child_id int;
                   DECLARE prev_id int;
                   SET prev_id = id;
                   SET child_id=0;
                   SELECT col3 into child_id 
                   FROM table1 WHERE col1=id ;
                   create TEMPORARY  table IF NOT EXISTS temp_table as (select * from table1 where 1=0);
                   truncate table temp_table;
                   WHILE child_id <> 0 DO
                     insert into temp_table select * from table1 WHERE col1=prev_id;
                     SET prev_id = child_id;
                     SET child_id=0;
                     SELECT col3 into child_id
                     FROM TABLE1 WHERE col1=prev_id;
                   END WHILE;
                   select * from temp_table;
                   END //
                  

                  我們使用臨時表來存儲輸出結果,并且由于臨時表是基于會話的,因此我們不會有任何關于輸出數據不正確的問題.

                  We are using temp table to store results of the output and as the temp tables are session based we wont there will be not be any issue regarding output data being incorrect.

                  SQL FIDDLE 演示

                  <打擊>試試這個查詢:

                  SQL FIDDLE Demo

                  Try this query:

                  SELECT 
                      col1, col2, @pv := col3 as 'col3' 
                  FROM 
                      table1
                  JOIN 
                      (SELECT @pv := 1) tmp
                  WHERE 
                      col1 = @pv
                  

                  SQL FIDDLE 演示:

                  | COL1 | COL2 | COL3 |
                  +------+------+------+
                  |    1 |    a |    5 |
                  |    5 |    d |    3 |
                  |    3 |    k |    7 |
                  

                  注意
                  parent_id 值應小于 child_id 才能使此解決方案起作用.

                  Note
                  parent_id value should be less than the child_id for this solution to work.

                  這篇關于如何在 MySQL 中進行遞歸 SELECT 查詢?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='LMlxc'></bdo><ul id='LMlxc'></ul>
                      <legend id='LMlxc'><style id='LMlxc'><dir id='LMlxc'><q id='LMlxc'></q></dir></style></legend>

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

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

                        <tfoot id='LMlxc'></tfoot>

                          • 主站蜘蛛池模板: 中文字幕偷拍 | 黄色性视频 | 国产亚洲欧美在线 | 久艹视频在线观看 | 69福利视频 | 日韩黄色录像 | 亚洲免费视频一区 | 国产精品一区二区三区四区 | 国产成人三级一区二区在线观看一 | 一本到av| 国产成人在线视频 | 天堂中文字幕免费一区 | 久久久久网 | 国产精品久久久久久久久借妻 | 国产精品国产三级国产专区52 | 久久伊人av| 天天综合天天做天天综合 | 天堂中文在线视频 | 欧美久久精品 | 欧美性受xxxx黑人xyx性爽 | 久久在线视频 | 一区二区精品在线 | 99xav| 日韩一区二区在线播放 | 免费观看的黄色网址 | 69免费视频| 一级片观看 | 国产激情视频在线 | 亚洲黄色三级 | 亚洲成人精品 | 久草福利视频 | 日韩一区在线视频 | 毛片视频网站 | 精品小视频 | 欧美日韩免费看 | 一级片在线视频 | 国产免费黄色 | 日韩欧美一区二区三区 | 欧美激情视频一区 | 国产日韩亚洲 | 日本免费网站 |