mysql學習筆記 第九天

來源:互聯網
上載者:User

標籤:style   blog   color   使用   資料   div   sp   log   on   

order by ,limit 和where子查詢的使用

order by:
  order by 列名1,[列名2],[列名3]...(結果先按列1進行排序,在列1的相同的情況下,再按照列2的排序,以此類推)。

mysql> select goods_id,goods_name,shop_price from goods    -> group by cat_id,shop_price;+----------+------------------------------+------------+| goods_id | goods_name                   | shop_price |+----------+------------------------------+------------+|       16 | 恒基偉業G101                 |     823.33 ||       20 | 三星BC01                     |     280.00 ||        8 | 飛利浦9@9v                   |     399.00 ||       15 | 摩托羅拉A810                 |     788.00 ||       19 | 三星SGH-F258                 |     858.00 ||       12 | 摩托羅拉A810                 |     983.00 ||       11 | 索愛C702c                    |    1300.00 ||       13 | 諾基亞5320 XpressMusic       |    1311.00 ||       10 | 索愛C702c                    |    1328.00 ||       31 | 摩托羅拉E8                   |    1337.00 ||       21 | 金立 A30                     |    2000.00 ||        9 | 諾基亞E66                    |    2298.00 ||       17 | 夏新N7                       |    2300.00 ||       32 | 魅族mx4                      |    3010.00 |

  limit的用法:
    limit的用法是限制顯示表的行數:limit A,B。A表示是從第幾行開始,B是顯示幾條資料,但是電腦內的第一條是從0開始算起的
    所以limit 0,1表示第一條資料(0可以省略)

mysql> select goods_id,goods_name from goods limit 0,1;+----------+------------+| goods_id | goods_name |+----------+------------+|        1 | KD876      |+----------+------------+1 row in set (0.00 sec)

         第三條到第五條資料:

mysql> select goods_id,goods_name from goods order by goods_id limit 2,3;+----------+---------------------+| goods_id | goods_name          |+----------+---------------------+|        4 | 諾基亞N85原裝充電器 ||        5 | 索愛原裝M2卡讀卡機  ||        6 | 勝創KINGMAX記憶卡   |+----------+---------------------+3 rows in set (0.00 sec)

where子查詢:
  因為我們可以把查詢出的資料表看成是一個暫存資料表,把查詢結果看成是變數,所以我們可以把用select查詢的結果看成是變數

mysql> select goods_id,goods_name,goods_name from goods    -> where goods_id =(select max(goods_id) from goods);+----------+------------+------------+| goods_id | goods_name | goods_name |+----------+------------+------------+|       32 | 魅族mx4    | 魅族mx4    |+----------+------------+------------+1 row in set (0.00 sec)

 

mysql學習筆記 第九天

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.