每天學習一點MySQL系列(3)— order by、desc、asc、where、is null、like

1)order by

--以字母順序排序數據,默認是升序
select column1 from table order by column1;
--按照多個列進行排序
select column1, column2, column3, column4 from table order by column1, column2;

2)desc

desc關鍵字只應用到直接位於它前面的列名;

如果想對多個列進行降序排序,必須對每個列指定desc關鍵字;

與desc相反的是asc,但是order by默認就是升序的。

--根據column1 降序排序
select column1 from table order by column1 desc 
--結合limit選擇出最大值
select column1 from table order by column1 desc  limit 1;

3)where

不等於的兩種表示方式:!= 和 <>;

在指定的兩個值之間:between a and b,包括開始值a和結束值b在內;

4)is null

--空值檢查:在一個列不包含值時,稱其爲包含空值null
select column1 from table where column2 is null;

5)like

select column1 from table where column2 like '%要匹配的關鍵字%';

通配符:%——匹配多個字符;下劃線_——匹配單個字符

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章