sql的一些知識 where

2022-03-02 07:43:30 字數 1257 閱讀 5712

簡單相同查詢,查詢age=22的三列資訊,並按照降序排列

select username,weight,age from userinfo where age=

22order

by weight desc

此外,where還支援一下判斷操作符

值得注意的是,如果比較的值為數值,則不需要加引號,如果是字元,則需要新增引號(限定引號)

select username,weight,age from userinfo where username=『李明』 order

by weight desc

between查詢某個範圍的值(中間用and),兩邊閉區間

select username,weight,age from userinfo where age between

20and

25

一下兩個語句效果一樣

select username,weight,age from userinfo where age>=

20and age<=

25

is null查詢 值為空的資訊(不是0)

select username,weight,age from userinfo where age is

null

and、or   和與或

select username,weight,age from userinfo where age>=

20and age<=

25

select username,weight,age from userinfo where age<=

20or age>=25

值得注意的是:and 和or是可以組合使用的。但在組合是 sql語句優先處理and,後處理or。因此,處理時最好加()消除歧義in(相當於or)

select username,weight,age from userinfo where age in(20,25)
not(否定後面的)

select username,weight,age from userinfo where

not age in(20,25,26)

SQL一些最基礎的知識

整數 int,smallint 數字 float,real 貨幣 money bit資料型別 儲存布林資料型別 image 可用來儲存影象 char,8000 固定長度的非unicode字元資料 varchar,8000 可變長度的非unicode資料 nchar,4000 固定長度的unicode...

一些經典的SQL

表結構 部門deptid,父級部門parentdeptid,資料庫的每一條記錄都記錄了自身id和父級部門id,現在要從某個部門查詢其下屬部門生成一棵部門關係樹,sql如下 select so.orgid,so.parentdeptid,so.orgname from sys orginfo so s...

SQL的一些筆記

強大的字串搜尋功能 regexp 例如 搜尋名字中含fiels的人,可用 1.select from table where name like fiels 2.select from table where regexp fiels 上面這個還看不出來功能的強大。接下來我們搜尋名字以fiels開頭...