MySQL學習筆記(二)

來源:互聯網
上載者:User

標籤:student   查詢語句   webp   not   esx   比較   關鍵詞   圖片   查詢   

轉載:http://www.cnblogs.com/best/p/6517755.html

1.運算式與條件查詢

 

where 關鍵詞用於指定查詢條件, 用法形式為: select 列名稱 from 表名稱 where 條件;

以查詢所有性別為女的資訊為例, 輸入查詢語句: select * from students where sex="女";

where 子句不僅僅支援 "where 列名 = 值" 這種名等於值的查詢形式, 對一般的比較運算的運算子都是支援的, 例如 =、>、<、>=、<、!= 以及一些擴充運算子 is [not] null、in、like 等等。 還可以對查詢條件使用 or 和 and 進行組合查詢, 以後還會學到更加進階的條件查詢方式, 這裡不再多做介紹。

樣本:

查詢年齡在21歲以上的所有人資訊: select * from students where age > 21;

查詢名字中帶有 "王" 字的所有人資訊: select * from students where name like "%王%";

查詢id小於5且年齡大於20的所有人資訊: select * from students where id<5 and age>20;

 

2.彙總函式

 

 

獲得學生總人數:select count(*) from students

獲得學生平均分:select avg(mark) from students

獲得最高成績:select max(mark) from students

獲得最低成績:select min(mark) from students

獲得學生總成績:select sum(mark) from students

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.