thinkphp 復合查詢

2021-09-27 08:37:00 字數 1364 閱讀 3718

$keywords_array=explode(' ',$keywords);

$like_where=array();

foreach ($keywords_array as $key => $value)

}$like_where=$keywords;

$like_where='or';

$kcondition['goods.goods_name']=$like_where;

$kcondition['goods.keywords']=$like_where;

$kcondition['_logic'] = 'or';

$condition['_complex'] = $kcondition;

$condition['goods.status']=array('in','1,2');

$condition['goods.is_del']=0;

列印出來的資料 

array(3) 

[1] => string(15) "與秋洗碗巾"

[2] => string(2) "or"

}["goods.keywords"] => array(3)

[1] => string(15) "與秋洗碗巾"

[2] => string(2) "or"

}["_logic"] => string(2) "or"

} ["goods.status"] => array(2)

["goods.is_del"] => int(0)

}string(283) "select count(*) as tp_count from `goods` where ( ( goods.goods_name like '%與秋洗碗巾%' or goods.goods_name = '與秋洗碗巾' ) or ( goods.keywords like '%與秋洗碗巾%' or goods.keywords = '與秋洗碗巾' ) ) and goods.status in ('1','2') and goods.is_del = 0 limit 1 "

觀察列印出來的資料,可以發現["_logic"] => string(2) "or"是用來連線goods.goods_name和goods_keywords 的,而兩個字段分別又帶有乙個or,這個or是用來連線每個字段裡面的條件的,比如

["goods.goods_name"] => array(3)

[1] => string(15) "與秋洗碗巾"

[2] => string(2) "or"

}表示 goods.goods_name like '%與秋洗碗巾%' or goods.goods_name = '與秋洗碗巾'

mysql 復合查詢

mysql 的復合查詢或者巢狀查詢,有表兩張,要以 clrtheme 表兩張為表列,將 clrcolor 橫向列出,故選擇巢狀查詢。mysql 復合巢狀查詢命令如下 select from clrtheme as t1,select from clrcolor where sort 0 as c1,...

MongoDB 復合查詢

復合查詢 and 並且 當查詢條件為多個欄位時,就會需要使用多欄位復合條件查詢。在查詢條件中指定多個字段條件,檢索出所有滿足條件的文件資料。eg 查詢person集合中年齡 age 大於30歲,並且名字 name 為 lucy 的資料。db.person.find 復合查詢 or 或 當有多個查詢條...

MySQL復合查詢

實際開發中往往資料來自不同的表,所以需要多表查詢。下面以乙個簡單的公司管理系統,有三張表emp,dept,salgrade來演示如何進行多表查詢。舉例 1.顯示雇員名,雇員工資以及所在部門的名稱。因為要查詢的資料來自兩個表,所以叫做多表查詢。select emp.ename,emp.sal,dept...