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

<legend id='6Vrw6'><style id='6Vrw6'><dir id='6Vrw6'><q id='6Vrw6'></q></dir></style></legend>
<tfoot id='6Vrw6'></tfoot>

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

        • <bdo id='6Vrw6'></bdo><ul id='6Vrw6'></ul>

        FIND_IN_SET() 與 IN()

        FIND_IN_SET() vs IN()(FIND_IN_SET() 與 IN())
          <bdo id='u7urD'></bdo><ul id='u7urD'></ul>

            <tbody id='u7urD'></tbody>

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

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

                • 本文介紹了FIND_IN_SET() 與 IN()的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我的數(shù)據(jù)庫中有 2 個(gè)表.一種用于訂單,一種用于公司.

                  I have 2 tables in my database. One is for orders, and one is for companies.

                  訂單具有以下結(jié)構(gòu):

                  OrderID     |     attachedCompanyIDs
                  ------------------------------------
                     1                     1,2,3
                     2                     2,4
                  

                  公司有這樣的結(jié)構(gòu):

                  CompanyID      |        name
                  --------------------------------------
                      1                 Company 1
                      2                 Another Company
                      3                 StackOverflow
                      4                 Nothing
                  

                  要獲取訂單的公司名稱,我可以執(zhí)行以下查詢:

                  To get an order's companies names, I can do a query as such:

                  SELECT name FROM orders,company
                  WHERE orderID = 1 AND FIND_IN_SET(companyID, attachedCompanyIDs)
                  

                  該查詢工作正常,但以下查詢無效.

                  That query works fine, but the following query does not.

                  SELECT name FROM orders,company
                  WHERE orderID = 1 AND companyID IN (attachedCompanyIDs)
                  

                  為什么第一個(gè)查詢有效,而第二個(gè)無效?

                  Why does the first query work but not the second one?

                  第一個(gè)查詢返回:

                  name
                  ---------------
                  Company 1
                  Another Company
                  StackOverflow
                  

                  第二個(gè)查詢只返回:

                  name
                  ---------------
                  Company 1
                  

                  這是為什么,為什么第一個(gè)查詢返回所有公司,而第二個(gè)查詢只返回第一個(gè)?

                  Why is this, why does the first query return all the companies, but the second query only returns the first one?

                  推薦答案

                  SELECT  name
                  FROM    orders,company
                  WHERE   orderID = 1
                          AND companyID IN (attachedCompanyIDs)
                  

                  attachedCompanyIDs 是一個(gè)標(biāo)量值,它被轉(zhuǎn)換為 INT(companyID 的類型).

                  attachedCompanyIDs is a scalar value which is cast into INT (type of companyID).

                  演員表只返回直到第一個(gè)非數(shù)字的數(shù)字(在你的情況下是逗號(hào)).

                  The cast only returns numbers up to the first non-digit (a comma in your case).

                  因此,

                  companyID IN ('1,2,3') ≡ companyID IN (CAST('1,2,3' AS INT)) ≡ companyID IN (1)
                  

                  PostgreSQL中,您可以將字符串轉(zhuǎn)換為數(shù)組(或首先將其存儲(chǔ)為數(shù)組):

                  In PostgreSQL, you could cast the string into array (or store it as an array in the first place):

                  SELECT  name
                  FROM    orders
                  JOIN    company
                  ON      companyID = ANY (('{' | attachedCompanyIDs | '}')::INT[])
                  WHERE   orderID = 1
                  

                  這甚至?xí)褂?companyID 上的索引.

                  and this would even use an index on companyID.

                  不幸的是,這在 MySQL 中不起作用,因?yàn)楹笳卟恢С謹(jǐn)?shù)組.

                  Unfortunately, this does not work in MySQL since the latter does not support arrays.

                  您可能會(huì)發(fā)現(xiàn)這篇文章很有趣(請(qǐng)參閱#2):

                  You may find this article interesting (see #2):

                  • MySQL 中的 10 件事(不會(huì)按預(yù)期工作)

                  更新:

                  如果逗號(hào)分隔列表中的值數(shù)量有一些合理的限制(比如不超過5),那么你可以嘗試使用這個(gè)查詢:

                  If there is some reasonable limit on the number of values in the comma separated lists (say, no more than 5), so you can try to use this query:

                  SELECT  name
                  FROM    orders
                  CROSS JOIN
                          (
                          SELECT  1 AS pos
                          UNION ALL
                          SELECT  2 AS pos
                          UNION ALL
                          SELECT  3 AS pos
                          UNION ALL
                          SELECT  4 AS pos
                          UNION ALL
                          SELECT  5 AS pos
                          ) q
                  JOIN    company
                  ON      companyID = CAST(NULLIF(SUBSTRING_INDEX(attachedCompanyIDs, ',', -pos), SUBSTRING_INDEX(attachedCompanyIDs, ',', 1 - pos)) AS UNSIGNED)
                  

                  這篇關(guān)于FIND_IN_SET() 與 IN()的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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è)先前值來決定接下來的 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ù)還是只是有問題的行?) - IT屋-程序員軟件開發(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ò)誤 沒有合適的驅(qū)動(dòng)程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫表作為 Spark 數(shù)據(jù)幀讀取?)
                  <legend id='1jzTc'><style id='1jzTc'><dir id='1jzTc'><q id='1jzTc'></q></dir></style></legend>
                  <i id='1jzTc'><tr id='1jzTc'><dt id='1jzTc'><q id='1jzTc'><span id='1jzTc'><b id='1jzTc'><form id='1jzTc'><ins id='1jzTc'></ins><ul id='1jzTc'></ul><sub id='1jzTc'></sub></form><legend id='1jzTc'></legend><bdo id='1jzTc'><pre id='1jzTc'><center id='1jzTc'></center></pre></bdo></b><th id='1jzTc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1jzTc'><tfoot id='1jzTc'></tfoot><dl id='1jzTc'><fieldset id='1jzTc'></fieldset></dl></div>

                  <small id='1jzTc'></small><noframes id='1jzTc'>

                    <tbody id='1jzTc'></tbody>

                    1. <tfoot id='1jzTc'></tfoot>

                          • <bdo id='1jzTc'></bdo><ul id='1jzTc'></ul>
                            主站蜘蛛池模板: 成人深夜福利 | 青青久在线视频 | 在线国产小视频 | 国产精品夜色一区二区三区 | 欧美一级全黄 | 黄色大片观看 | 精品久久久久久亚洲精品 | 亚洲成人a v | 美女天天操 | 久久精品毛片 | 国产高清一区二区三区 | 亚洲高清一区二区三区 | 色悠悠久 | 国产在线精品一区二区 | 日本久久视频 | 婷婷久久综合 | 日韩三片 | 亚洲精品一区二三区不卡 | 成人h片在线观看 | 欧美福利 | 久久免费精品 | 免费激情av | 国产精品99久久免费观看 | 日韩羞羞| 成人精品一区二区三区中文字幕 | 久久久久久艹 | 嫩草国产| 国产精品99久久久久久动医院 | 日韩欧美一区二区三区四区 | 精品国产乱码一区二区三 | 国产成人a亚洲精品 | 国产丝袜一区二区三区免费视频 | 天天操夜夜拍 | 亚洲成人免费视频在线 | 久久久免费电影 | 青青草综合网 | 午夜播放器在线观看 | 久久久69| 人人亚洲 | 欧美亚洲第一区 | 精品视频一区二区三区在线观看 |