資料庫(4)查詢

2021-08-07 22:56:43 字數 1031 閱讀 3818

基本語法

select * from 表名;

消除重複行

select distinct *** from table;

使用where子句對錶中的資料篩選,結果為true的行會出現在結果集中

select * from 表名 where 條件;

比較運算子

等於=

大於》大於等於》=

小於<

小於等於<=

不等於!=或<>

查詢編號大於3的學生

select * from students where id>3;

邏輯運算子

and

ornot

查詢編號大於3的女同學

select * from students where id>3 and gender=0;

模糊查詢

like

%表示任意多個任意字元

_表示乙個任意字元

eg:

select * from students where sname like 『黃%』 or sname like 『%靖%』;

範圍查詢

1)不連續查詢

select* from table where id in(1, 3, 8);

2)連續查詢

select* from table where id between 1 and 9;

空判斷

注意:null 與 『』是不同的

select * from table where *** is null;

優先順序

1)小括號,not,比較運算子,邏輯運算子

2)and比or先運算,

4 MySQL資料庫 簡單查詢

1.簡單查詢 1.1查詢單個字段語法 select 查詢列表 from 表名 例子 查詢單個欄位 查詢員工姓名 select ename from emp 1.2查詢多個字段 例子 查詢多個欄位 查詢員工姓名和工資 select ename,sal from emp 1.3查詢所有字段select ...

實驗4 資料庫的連線查詢

4.1實驗目的及要求 掌握簡單表的資料查詢 資料排列和表鏈結查詢的操作方法 4.2實驗內容 簡單查詢操作和連線查詢操作。4.3實驗步驟 4.3.1連線查詢 1.查詢每個學生及選秀課程情況 比較 笛卡爾集 select student.sc.from student,sc 自然連線 select st...

資料庫模糊查詢4種用法

1,表示任意0個或多個字元。可匹配任意型別和長度的字元,有些情況下若是中文,請使用兩個百分號 表示。比如 select from user where u name like 三 將會把u name為 張三 張貓三 三腳貓 唐三藏 等等有 三 的記錄全找出來。另外,如果需要找出u name中既有 三...