MySQL之where條件資料篩選

2022-09-09 05:00:16 字數 2273 閱讀 6165

語法:

-- select * from 表名 where 條件;
測試資料:

-- 建表語句

create table `student` (

`sid` int(11) primary key auto_increment,

`sname` varchar(20) not null,

`***` varchar(10) default null,

`isdelete` tinyint(1) default 0

)charset=utf8;

-- 插入資料

insert into `student`(`sid`, `sname`, `***`) values

(0, '達摩', '男'),

(0, '典韋', '男'),

(0, '曹操', '男'),

(0, '鍾無艷', '女'),

(0, '孫悟空', '男'),

(0, '蘭陵王', '男'),

(0, '程咬金', '男'),

(0, '劉備', '男'),

(0, '劉禪', '男'),

(0, '孫尚香', '女'),

(0, '孫臏', '男');

-- 查詢sid小於3的學生資訊

select * from student where sid<3;

執行結果:

-- 查詞 sid 大於 8 並且 *** 為 男 的學生

select * from student where sid>8 and ***='男';

-- 查詢 sid 大於等於 10 或者 sid 小於 3 的學生;

select * from student where sid>=10 or sid<3;

-- 查詢 sid 不大於 3 的學生

select * from student where not sid>3;

執行結果:

優先順序:not>and>or

注意:and 比 or 優先運算。如果同時出現並希望 or 優先運算,可以使用小括號。

執行結果:

-- 查詢沒有性別資訊的同學

select * from student where *** is null;

執行結果:

注意:null』 』的不同。null就是空,在計算機中不占用任何記憶體;』 』為空字元

串,需要佔據一定記憶體。

請檢視mysql之函式一節

請檢視group by分組查詢一節

請檢視group by分組查詢一節

示例:

select * from student

where ***='女'

order by sid desc;

執行結果:

示例:

select * from student limit 1,5;
執行結果:

語法:select * from 表名 where 查詢條件 limit (curpage - 1)*pagesize,pagesize;

說明:curpage是當前第幾頁;pagesize是一頁多少條記錄

MySQL之where條件查詢

單錶查詢是mysql查詢中的一種常見的查詢方式,而where語句塊則在單錶查詢語句中起到指定查詢過濾條件的功能。語法為 select 字段列表 表示式 from table name where 條件 order by 字段列表 說明 相當於按照表中字段順序羅列表中的所有字段 字段列表 當查詢結果只...

MySQL核心技術之「WHERE條件」

先看一下呼叫鏈 join optimize make join select join tab set condition 這裡就把condition賦值給了join tab。那麼condition是如何產生的呢?是在parse乙個query的時候,具體的是yacc產生的 不用特意關心。舉例來說的,...

mysql匯出錶帶where條件

引數介紹 c 完整的insert語句,包含欄位名的insert t 不要寫 建立資訊 set gtid purged mysql 5.6 引入了 gtid 特性 auto 預設值 對於啟用 gtid 伺服器,會輸出 set global.gtid purged 語句 對於沒有啟動或者不支援 gtid...