我需要你的幫助。
我有一個無法執行的 sql 查詢問題。
我有兩個表,patients and user在患者表中我有欄位, name,last name, personal_id, strikes在users表中我有一個名為 status. 我澄清一下,personal_id是公司分配的代碼,不同于PK。
在系統邏輯中,用戶可能因兩個原因被“禁用”。
1.-管理員把用戶的狀態放在Inactive
2.-用戶有3次或更多的罷工。
所以我試圖做的查詢如下。
給定 a value,將所有匹配的用戶回傳給我 personal_id OR last name,并且用戶還處于非活動狀態 ( Either for reasons 1 or 2)
$patients= DB::table('patiens')
->join('users','patiens.User_ID','=','users.id')
->where('users.status','=','Inactive')
->orwhere('patiens.strikes','>=',3)
->where('patiens.last_name','like','%'.$date.'%')
->orwhere('patiens.personal_id','like','%'.$date.'%')
->get();
基本上我需要我的查詢來實作這一點:
This...
->where('users.status','=','Inactive')
->orwhere('patiens.strikes','>=',3)
AND ALSO
->where('patiens.last_name','like','%'.$date.'%')
->orwhere('patiens.personal_id','like','%'.$date.'%')
基本上,首先提取All Inactive然后在該串列中查找所有匹配項
uj5u.com熱心網友回復:
您可以在回呼中嵌套條件:
$patients= DB::table('patiens')
->join('users','patiens.User_ID','=','users.id')
->where(function ($query) {
$query->where('users.status','=','Inactive')
->orwhere('patiens.strikes','>=',3);
})->where(function ($query) use ($date) {
$query->where('patiens.last_name','like','%'.$date.'%')
->orwhere('patiens.personal_id','like','%'.$date.'%');
})
->get();
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/383436.html
上一篇:當我點擊按鈕時,我想更新資料庫
下一篇:更新并附加到特定列中的所有專案
