重新瞭解數據庫——DQL(查詢)

DQL是數據庫查詢語言,就是我們平時最常用的查詢的語句。

select完整語法

查詢

select * from 表名  --查詢表中所有數據

select 字段,字段 from 表名;   --查詢指定字段

給查出的數據加內容

select concat('姓名:',name) as 新名字 from 表名;

修改全部的查詢結果

select score+1 from 表名;    --表中查出的所有分數+1

通過別名查詢

select 字段 as 別名,字段 as 別名 from 表名;

 

去重查詢

去除查詢結果中重複的數據
select distinct 字段 from 表名;

 

AND、OR、Not

--查詢成績在90-100之間的 
select score from 表 where score>=90 and score<=100;
select score from 表 where score between 90 and 100;

--查詢成績爲空的學生姓名
select name from student where score is null;

--查詢成績不爲空的學生姓名
select name from student where score is not null;

 

模糊查詢(like、in)

like + %(代表0到任意個字符)或  _(一個字符)

select name from student where name like '劉%';  --查詢名字中姓劉的

select name from student where name like '劉_';  --查詢名字姓劉且後面只有一個字的

in

--查詢在河南的學生姓名
select name from student where address in ('河南');

 

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