【轉-記】mysql總結

來源:互聯網
上載者:User

標籤:esc   app   範圍查詢   name   最大   查詢   lin   des   根據   


1 | 查詢所有資料 

 

select * from Info 查所有資料

select Code,Name from Info 查特定列

 

 2 | 根據條件查 

 

select * from Info where Code=‘p001‘ 一個條件查詢

select * from Info where Code=‘p001‘ and Nation=‘n001‘ 多條件 並關係 查詢

select * from Info where Name=‘胡軍‘ or Nation=‘n001‘ 多條件 或關係 查詢

select * from Car where Price>=50 and Price<=60 範圍查詢

select * from Car where Price between 50 and 60 範圍查詢

 

 3 | 模糊查詢 

 

select * from Car where Name like ‘%型‘ %萬用字元代表任意多個字元

select * from Car where Name like ‘%奧迪%‘ _萬用字元代表任意一個字元

select * from Car where Name like ‘_馬%‘

 

 4| 排序 

 

select * from Car order by Price asc 按照價格升序排列

select * from Car order by Price desc 按照價格降序排列

select * from Car order by Price,Oil 按照兩列進行排序,前面的為主要的

 

 5 | 統計函數(彙總函式)

 

select count(Code) from Car 查詢表中有多少條資料

select max(Price) from Car 取價格的最大值

select min(Price) from Car 取價格的最小值

select sum(Price) from Car 取價格的總和

select avg(Price) from Car 取價格的平均值

 

 6 | 分組查詢 

 

select Brand from Car group by Brand having count(*)>2 查詢所有系列中數量大於2的

 

 7 | 分頁查詢 

 

select * from Car limit 0,5 跳過幾條資料取幾條資料

 

 8 | 去重查詢 

 

select distinct Brand from Car

【轉-記】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.