2016.3.25(mySQL簡單的資料查詢)

來源:互聯網
上載者:User

標籤:

要從資料庫中查詢,要使用SQL的select語句,標準select查詢有select子句,where子句,order by子句組成。

查詢資料的標準結構為:select 列名 from 表名 where 條件 order by 列名 asc(升序)/desc(降序)

查詢操作的分類:1、投影操作,指定查詢結果中能顯示哪些列
2、選擇操作,指定哪行出現在結果中
3、排序操作,指定查詢的結果以什麼樣的順序顯示

投影操作:select 列1,列2 from 表名

表首碼:select 表名.列名 from 表名

列別名(才顯示結果的時候更改列名):select 列 as 別名 from 表名

計算資料行:select 列名 計算符 計算量

排除重複資料:select distinct 列名 from 表名 (多個列時,使用組合匹配,只有多個列相同時才會排除)

表中列拼接:select concat(列1,列2,列3) from 表名

返回限定數的查詢:select 列1 ,列2 from 表名 limit 開始序號,返回的行數
注意:limit 序號是從0開始,limit只能用於mySQL當中

查詢表中符合約束條件的個數:select count(列名)from 表名 where 約束條件

查詢表中條件1至條件2的資料:select 列名 from 表名 where 列名 between 條件1 and 條件2

查詢合格資料:select 列名 from 表名 where 列名 in(約束條件)

查詢排除條件的資料:select 列名 from 表名 where 列名 out(約束條件)


模糊查詢:

查詢列A,列B當列C有兩個字元的資料:select 列A,列B from 表名 where 列C like‘_ _‘

查詢表中列C含有’張‘字元的資料:select * from 表名 where 列名C like ‘張%‘

轉譯a後的內容:select * from 表名 where 列名 like ‘%a%%‘ escape ‘a‘

查詢表中所有列名為空白的資料:select * from 表名 where 列名 is null

查詢表中所有列名不為空白的資料:select * from 表名 where 列名 is not null


基本的查詢SQL的執行順序:1、執行from 2、where 條件 3.select 投影列 4.執行Oder by 排序

2016.3.25(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.