查詢表示式

2022-03-07 22:26:20 字數 3771 閱讀 8416

版本

新增功能

5.0.9

比較運算增加閉包子查詢支援

5.0.4

支援對同乙個字段多次呼叫查詢方法

查詢表示式支援大部分的sql查詢語法,也是

thinkphp

查詢語言的精髓,查詢表示式的使用格式:

where

('欄位名'

,'表示式'

,'查詢條件'

);where

or('欄位名'

,'表示式'

,'查詢條件'

);

表示式不分大小寫,支援的查詢表示式有下面幾種,分別表示的含義是:

表示式含義

eq、=

等於(=)

neq、<>

不等於(<>)

gt、>

大於(>)

egt、>=

大於等於(>=)

lt、<

小於(<)

elt、<=

小於等於(<=)

like

模糊查詢

[not] between

(不在)區間查詢

[not] in

(不在)in 查詢

[not] null

查詢字段是否(不)是null

[not] exists

exists查詢

exp表示式查詢,支援sql語法

> time

時間比較

< time

時間比較

between time

時間比較

notbetween time

時間比較

表示式查詢的用法示例如下:

例如:

where

('id'

,'eq'

,100

);where

('id'

,'='

,100

);

和下面的查詢等效

where

('id'

,100

);

表示的查詢條件就是

id = 100

例如:

where

('id'

,'neq'

,100

);where

('id'

,'<>'

,100

);

表示的查詢條件就是

id <> 100

例如:

where

('id'

,'gt'

,100

);where

('id'

,'>'

,100

);

表示的查詢條件就是

id > 100

例如:

where

('id'

,'egt'

,100

);where

('id'

,'>='

,100

);

表示的查詢條件就是

id >= 100

例如:

where

('id'

,'lt'

,100

);where

('id'

,'<'

,100

);

表示的查詢條件就是

id < 100

例如:

where

('id'

,'elt'

,100

);where

('id'

,'<='

,100

);

表示的查詢條件就是

id <= 100

例如:

where

('name'

,'like'

,'thinkphp%'

);

查詢條件就變成

name like 'thinkphp%'

v5.0.5+

版本開始,like查詢支援使用陣列

where

('name'

,'like'

,['%think'

,'php%'

],'or'

);

``

查詢條件支援字串或者陣列,例如:

where

('id'

,'between'

,'1,8'

);

和下面的等效:

where

('id'

,'between',[1

,8]);

查詢條件就變成

id between 1 and 8

查詢條件支援字串或者陣列,例如:

where

('id

','not

in','1,

5,8');

和下面的等效:

where

('id

','not

in',[1,

5,8]);

查詢條件就變成

id not in (1,5, 8)

[not] in

查詢支援使用閉包方式

查詢字段是否(不)是

null

,例如:

where

('name'

, null

);where

('title'

,'null'

);where

('name'

,'not null'

);

如果你需要查詢乙個欄位的值為字串

null或者not null

,應該使用:

where

('title'

,'='

, 'null'

);where

('name'

,'='

, 'not null'

);

支援更複雜的查詢情況 例如:

where

('id

','in

','1,3

,8');

可以改成:

where

('id'

,'exp'

,' in (1,3,8) '

);

exp

查詢的條件不會被當成字串,所以後面的查詢條件可以使用任何sql支援的語法,包括使用函式和欄位名稱。

查詢表示式

這個特性使得你可以在c 中使用sql類似風格的語句,也被稱作linq 語言整合查詢 舉例來說,你可以這樣描述你的資料 ublic class coordinate 在c 裡,你可以像下面一樣輕鬆的宣告乙個資料庫表的邏輯等同式 use object and collection initializer...

查詢表示式解析

查詢表示式解析 1 ienumerablequery from s in names where s.length 5 orderby s select s.toupper 在語義上等同於如下 方法風格 基於方法 的查詢 ienumerablequery names where s s.length...

查詢表示式理解

listp new list p.add new product p.add new product p.add new product p.add new product p.add new product p.add new product ienumerablelist2 from x in ...