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

  • <small id='duSCI'></small><noframes id='duSCI'>

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

      3. <tfoot id='duSCI'></tfoot>

        MySQL - 在選擇時獲取行號

        MySQL - Get row number on select(MySQL - 在選擇時獲取行號)

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

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

                  本文介紹了MySQL - 在選擇時獲取行號的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  如果項目已排序,我可以運行 select 語句并獲取行號嗎?

                  Can I run a select statement and get the row number if the items are sorted?

                  我有一張這樣的桌子:

                  mysql> describe orders;
                  +-------------+---------------------+------+-----+---------+----------------+
                  | Field       | Type                | Null | Key | Default | Extra          |
                  +-------------+---------------------+------+-----+---------+----------------+
                  | orderID     | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
                  | itemID      | bigint(20) unsigned | NO   |     | NULL    |                |
                  +-------------+---------------------+------+-----+---------+----------------+
                  

                  然后我可以運行此查詢以按 ID 獲取訂單數:

                  I can then run this query to get the number of orders by ID:

                  SELECT itemID, COUNT(*) as ordercount
                  FROM orders
                  GROUP BY itemID ORDER BY ordercount DESC;
                  

                  這給了我表格中每個 itemID 的計數,如下所示:

                  This gives me a count of each itemID in the table like this:

                  +--------+------------+
                  | itemID | ordercount |
                  +--------+------------+
                  |    388 |          3 |
                  |    234 |          2 |
                  |   3432 |          1 |
                  |    693 |          1 |
                  |   3459 |          1 |
                  +--------+------------+
                  

                  我也想得到行號,所以我可以知道 itemID=388 是第一行,234 是第二行,等等(本質上是訂單,而不僅僅是原始計數).我知道當我得到結果集時我可以在 Java 中執行此操作,但我想知道是否有一種方法可以完全在 SQL 中處理它.

                  I want to get the row number as well, so I could tell that itemID=388 is the first row, 234 is second, etc (essentially the ranking of the orders, not just a raw count). I know I can do this in Java when I get the result set back, but I was wondering if there was a way to handle it purely in SQL.

                  更新

                  設置等級會將其添加到結果集中,但未正確排序:

                  Setting the rank adds it to the result set, but not properly ordered:

                  mysql> SET @rank=0;
                  Query OK, 0 rows affected (0.00 sec)
                  
                  mysql> SELECT @rank:=@rank+1 AS rank, itemID, COUNT(*) as ordercount
                      -> FROM orders
                      -> GROUP BY itemID ORDER BY rank DESC;
                  +------+--------+------------+
                  | rank | itemID | ordercount |
                  +------+--------+------------+
                  |    5 |   3459 |          1 |
                  |    4 |    234 |          2 |
                  |    3 |    693 |          1 |
                  |    2 |   3432 |          1 |
                  |    1 |    388 |          3 |
                  +------+--------+------------+
                  5 rows in set (0.00 sec)
                  

                  推薦答案

                  看看這個.

                  將您的查詢更改為:

                  SET @rank=0;
                  SELECT @rank:=@rank+1 AS rank, itemID, COUNT(*) as ordercount
                    FROM orders
                    GROUP BY itemID
                    ORDER BY ordercount DESC;
                  SELECT @rank;
                  

                  最后一個選擇是你的計數.

                  The last select is your count.

                  這篇關于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='fotQr'></tbody>
                    <bdo id='fotQr'></bdo><ul id='fotQr'></ul>

                      <tfoot id='fotQr'></tfoot>

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

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

                            <legend id='fotQr'><style id='fotQr'><dir id='fotQr'><q id='fotQr'></q></dir></style></legend>
                            主站蜘蛛池模板: 免费色网址 | 免费黄色a视频 | 最新av中文字幕 | 欧美精品中文字幕久久二区 | 黄视频免费 | 天天躁日日躁xxxxaaaa | 亚洲欧美一区二区三区国产精品 | 国产精品久久99 | 伊人精品 | 我我色综合 | 欧洲一区在线观看 | 国产观看 | 91精品国产91久久综合桃花 | 国内精品视频 | 日韩精品一区二区三区中文字幕 | 97国产成人 | 久久九| 国产激情一区二区三区 | 久久免费视频1 | 97综合在线 | 色桃网| 在线免费看黄 | 极品粉嫩国产48尤物在线播放 | www国产成人免费观看视频 | 伊人艹 | 日一区二区 | 国产精久久久久久久妇剪断 | 视频在线日韩 | 精精国产xxxx视频在线野外 | 成人黄色av | 日日草夜夜草 | h免费观看| 欧美a在线 | 福利av在线 | 久久久免费少妇高潮毛片 | 久久综合一区 | 日韩成人免费在线视频 | 国产区精品 | 一区二区三区日韩 | 99爱国产 | 亚洲欧美视频 |