sql查詢 範圍查詢(區間查詢)

2022-02-06 06:58:12 字數 972 閱讀 6619

1 --範圍查詢(區間查詢)

2 --in

()3 --查詢年齡為18,28,38的人 select *from student where age=18 or age=28 or age=38;

4 select *from student where age in(18,28,38);

5 --not

in6 --查詢年齡為18,28,38的人 select *from student where not (age=18 or age=28 or age=38);

7 select *from student where age not

in (18,28,38);

8 --between...and

...9 --查詢12-18的人

10 select *from student where age between 12 and 18;

11 -- not between...and

...12 -- 查詢年齡不在12-18的人

13 select *from student where age not between 12 and 18;

14 -- 失敗select *from student where age not (between 12 and 18);

1516

17 --判斷空

18 -- is

null

19 --判斷年齡是否為空

20 select *from student where age is

null;

21 -- is

notnull

22 --判斷年齡不為空

23 select *from student where age is

not null;

《SQL語句WHERE查詢 範圍查詢 模糊查詢》

0 儲存過程開頭變數定義 fbegindate varchar 10 單據起始日期 fenddate varchar 10 單據截止日期。fitemid varchar 50 fitemid2 varchar 50 fcust varchar 50 fcust2 varchar 50 fstatus...

mysql 範圍查詢 Mysql 範圍查詢優化

1.2 另外,對於btree索引,index和乙個常量值通過 between,或者 操作符做比較 1.3 對於所有型別的index,多範圍條件通過 or and關鍵字組合形式 常量值 在之前的描述中意味著 2.1 查詢字串的常量形式 2.2 const 或者system表的一列 也只有一列 的自連線...

mysql區間查詢 MySQL區間分組查詢

假設a表為會員資訊表,需要統計男性會員年齡各階段的出現的人數 create table a id int 11 unsigned not null auto increment,name varchar 255 not null default comment 會員名稱 tinyint 1 unsi...