MySQL學習總結----單表資料查詢

來源:互聯網
上載者:User

標籤:mysql

MySQL學習總結----單表資料查詢

=================================================================================

一、基本資料記錄查詢

=================================================================================

1、簡單資料查詢

  • select id,name,sex,class,address from qiuuuu;查詢表qiuuuu中的所有資訊;

  • select id,name,sex from qiuuuu;查詢表qiuuuu中的欄位id,name,sex三個屬性的所有資訊;

  • select * from qiuuuu;查詢表qiuuuu中的所有欄位的所有資訊;

2、避免重複資料查詢DISTINCT

  • select distinct class from qiuuuu;查詢表qiuuuu中關於屬性class的所有記錄,無重複顯示;

3、四則運算子查詢

+ 加法
- 減法
* 乘法
/ 除法
% 求餘
  • select id*2 from qiuuuu

4、顯示格式資料查詢

mysql> select concat(name,‘------test:‘,id) hello from qiuuuu;

concat連接字串,括弧裡面接屬性名稱和字串,緊跟列印出來的表格名稱。

+-------------------+

| hello             |

+-------------------+

| james------test:1 |

| allen------test:2 |

| zhang------test:3 |

| xi------test:3    |

| xi------test:3    |

| li------test:3    |

| wang------test:3  |

+-------------------+

7 rows in set (0.00 sec)

=================================================================================

二、條件資料記錄查詢

=================================================================================

    在MySQL資料庫中,通過SQL語句select來實現查詢,同時通過關鍵字where對所查詢的資料記錄進行過濾,文法如下:

select 屬性名稱1,屬性名稱2,屬性名稱3,.....,屬性名稱n from qiuuuu where .......

    在where後面可以接一下關鍵字:

  • between and

  • is null

  • in

  • like

    比較子有:

> 大於
< 小於
= 等於
!=或<> 不等於
>= 大於等於
<= 小於等於

    邏輯運算子有:

and或&&
or或|| 邏輯或
xor 異或
not或!


=================================================================================

三、排序資料記錄查詢

=================================================================================

select 屬性名稱1,屬性名稱2,屬性名稱2,......,屬性名稱n from 表名 

            where CONDITION order by 屬性名稱m [asc|desc] [,屬性名稱i [asc|desc],]

1、按照單欄位排序

  • select id from qiuuuu where class=‘3‘ order by id desc; 降序

  • select id from qiuuuu where class=‘3‘ order by id asc; 升序(預設升序排列)

2、按照多欄位排序

select * from qiuuuu where class=‘3‘ order by id desc,address asc;


=================================================================================

四、限制資料記錄查詢數量

=================================================================================




================================================================================

五、統計函數和分組資料記錄查詢

=================================================================================






















本文出自 “doublelinux” 部落格,謝絕轉載!

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.