MySQL基本操作-SQL查詢語句

來源:互聯網
上載者:User

標籤:

1.查詢資料

   select  屬性列表

            from  表名和視圖列表

            [where  條件運算式1]

            [group by 屬性名稱1  [having 條件運算式2] [with rollup最後加一條記錄是上面記錄的總和]]  //按照屬性名稱1指定的欄位分組,有having則要滿足條件運算式2

     [order  by 屬性名稱2  [asc|desc]]

      where查詢條件:

      比較          =、<、<=、 >、>=、!=、<>、!>、!<

      指定範圍     between and、not between and

      指定集合     in、not in

      匹配字元     like、not like <%:代表任意長度字串,_:代表單個字元>

      是否為空白值  is null、is not null

eg:select * from test0 where id in (1001,1004,1005);

     select * from test0 where id between 1002 and 1005;

   select * from test0 where id < 1004 and name like ‘h_h_‘; //兩個條件均滿足

     select * from test0 where id < 1004 or name like ‘h%‘; // 滿足其中一個便可

   select distinct name from test0;   //查詢結果不重複 

   select id,group_concat(name) from test0 group by name;//將name分組中指定欄位值都顯示出來

   select name,count(name) from test0 group by name;//將name分組的每一組記錄數統計出來

   select name,count(name) from test0 group by name having count(name) > 1; //顯示記錄數大於1的

     having運算式是作用於分組後的記錄,而where作用於表或者視圖。

   select name,count(name) from test0 group by name with rollup;

     select * from test0 limit 3; //只顯示3條記錄

     select * from test0 limit 1,3; //從第2條記錄起顯示3條記錄

     

MySQL基本操作-SQL查詢語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.