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

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

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

      按 SQL IN() 子句中值的順序排序

      Ordering by the order of values in a SQL IN() clause(按 SQL IN() 子句中值的順序排序)
    1. <legend id='8XrZu'><style id='8XrZu'><dir id='8XrZu'><q id='8XrZu'></q></dir></style></legend>

                <bdo id='8XrZu'></bdo><ul id='8XrZu'></ul>

                <tfoot id='8XrZu'></tfoot>

                  <tbody id='8XrZu'></tbody>
              • <small id='8XrZu'></small><noframes id='8XrZu'>

                <i id='8XrZu'><tr id='8XrZu'><dt id='8XrZu'><q id='8XrZu'><span id='8XrZu'><b id='8XrZu'><form id='8XrZu'><ins id='8XrZu'></ins><ul id='8XrZu'></ul><sub id='8XrZu'></sub></form><legend id='8XrZu'></legend><bdo id='8XrZu'><pre id='8XrZu'><center id='8XrZu'></center></pre></bdo></b><th id='8XrZu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8XrZu'><tfoot id='8XrZu'></tfoot><dl id='8XrZu'><fieldset id='8XrZu'></fieldset></dl></div>
                本文介紹了按 SQL IN() 子句中值的順序排序的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我想知道是否有(可能是更好的方法)按 IN() 子句中值的順序排序.

                問題是我有 2 個(gè)查詢,一個(gè)獲取所有 ID,第二個(gè)獲取所有信息.第一個(gè)創(chuàng)建我希望第二個(gè)排序的 ID 的順序.ID 以正確的順序放在 IN() 子句中.

                所以它會(huì)是這樣的(極其簡化):

                SELECT id FROM table1 WHERE ... ORDER BY display_order, nameSELECT name, description, ... WHERE id IN ([id's from first])

                問題是第二個(gè)查詢返回的結(jié)果與將 ID 放入 IN() 子句中的順序不同.

                我發(fā)現(xiàn)的一個(gè)解決方案是將所有 ID 放入帶有自動(dòng)遞增字段的臨時(shí)表中,然后將其加入第二個(gè)查詢中.

                有更好的選擇嗎?

                注意:由于第一個(gè)查詢是由用戶"運(yùn)行的,而第二個(gè)查詢是在后臺(tái)進(jìn)程中運(yùn)行的,因此無法使用子查詢將 2 個(gè)查詢合并為 1 個(gè)查詢.>

                我正在使用 MySQL,但我認(rèn)為讓它記錄其他 DB 的選項(xiàng)可能會(huì)很有用.

                解決方案

                使用 MySQL 的 FIELD() 函數(shù):

                SELECT 名稱、描述、...從 ...WHERE id IN([ids, any order])ORDER BY FIELD(id, [ids in order])

                FIELD() 將返回與第一個(gè)參數(shù)相等的第一個(gè)參數(shù)的索引(第一個(gè)參數(shù)本身除外).

                FIELD('a', 'a', 'b', 'c')

                將返回 1

                FIELD('a', 'c', 'b', 'a')

                將返回 3

                如果您將 id 以相同的順序粘貼到 IN() 子句和 FIELD() 函數(shù)中,這將完全符合您的要求.

                I am wondering if there is away (possibly a better way) to order by the order of the values in an IN() clause.

                The problem is that I have 2 queries, one that gets all of the IDs and the second that retrieves all the information. The first creates the order of the IDs which I want the second to order by. The IDs are put in an IN() clause in the correct order.

                So it'd be something like (extremely simplified):

                SELECT id FROM table1 WHERE ... ORDER BY display_order, name
                
                SELECT name, description, ... WHERE id IN ([id's from first])
                

                The issue is that the second query does not return the results in the same order that the IDs are put into the IN() clause.

                One solution I have found is to put all of the IDs into a temp table with an auto incrementing field which is then joined into the second query.

                Is there a better option?

                Note: As the first query is run "by the user" and the second is run in a background process, there is no way to combine the 2 into 1 query using sub queries.

                I am using MySQL, but I'm thinking it might be useful to have it noted what options there are for other DBs as well.

                解決方案

                Use MySQL's FIELD() function:

                SELECT name, description, ...
                FROM ...
                WHERE id IN([ids, any order])
                ORDER BY FIELD(id, [ids in order])
                

                FIELD() will return the index of the first parameter that is equal to the first parameter (other than the first parameter itself).

                FIELD('a', 'a', 'b', 'c')

                will return 1

                FIELD('a', 'c', 'b', 'a')

                will return 3

                This will do exactly what you want if you paste the ids into the IN() clause and the FIELD() function in the same order.

                這篇關(guān)于按 SQL 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ù)幀讀取?)

                1. <small id='7M0F9'></small><noframes id='7M0F9'>

                  • <legend id='7M0F9'><style id='7M0F9'><dir id='7M0F9'><q id='7M0F9'></q></dir></style></legend>

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

                        <tfoot id='7M0F9'></tfoot>

                          <bdo id='7M0F9'></bdo><ul id='7M0F9'></ul>

                        • 主站蜘蛛池模板: 中文字幕成人在线 | 亚洲国产欧美精品 | 人人爽人人草 | avhd101在线成人播放 | 亚洲国产一区在线 | 国产高清av免费观看 | 成人免费一区二区三区牛牛 | 国产精品一区二 | 国产一极毛片 | 久久精品一 | 久久一视频 | 欧美国产精品久久久 | 亚洲午夜av久久乱码 | 亚洲精品一区二区在线观看 | 亚洲欧美一区二区三区国产精品 | 国产一区二区av | 欧洲一区二区视频 | 久久夜夜 | 人人干在线视频 | 三级成人片 | 国产欧美精品 | 龙珠z国语版在线观看 | 精品日韩一区二区三区av动图 | 97av视频在线观看 | 国产成人99久久亚洲综合精品 | 亚洲激情视频在线 | 日韩一区二区三区四区五区六区 | 91精品久久久久久久久久入口 | 亚洲高清在线 | 中文av在线播放 | 成人在线视频网 | 九九视频在线观看 | 国产亚洲人成a在线v网站 | 欧美一区二区三区在线 | 一区二区三区在线 | 国产精品久久久久久久久久久久 | 午夜视频免费在线 | 91资源在线 | 激情国产在线 | 91九色网站 | 久久久久久久久久久久久久av |