Laravel 雄辩的地点和地点;“分;或
我有一个关于Laravel 雄辩的地点和地点;“分;或,laravel,eloquent,Laravel,Eloquent,我有一个关于WHERE条款的问题 在这个问题上,我想说 SELECT ... FROM ... WHERE link.hos_id = $hos_id AND outcome.otc_otrdischargedate = $td AND outcome.otc_outcome LIKE ['%ICU%', '%I.C.U%', '%L3%'] 但是它读起来是这样的 SELECT ... FROM ... WHERE link.hos_id = $hos_id AND outcome
WHERE
条款的问题
在这个问题上,我想说
SELECT ...
FROM ...
WHERE link.hos_id = $hos_id
AND outcome.otc_otrdischargedate = $td
AND outcome.otc_outcome LIKE ['%ICU%', '%I.C.U%', '%L3%']
但是它读起来是这样的
SELECT ...
FROM ...
WHERE link.hos_id = $hos_id
AND outcome.otc_otrdischargedate = $td
OR outcome.otc_outcome LIKE ['%ICU%', '%I.C.U%', '%L3%']
laravel查询的结构应该如何与第一个示例一样
$matchThese = ['link.hos_id' => $hos_id, 'outcome.otc_otrdischargedate' => $td];
$icu = DB::table('link')
->join('demographic', 'link.lnk_dmgid', '=', 'demographic.dmg_id')
->join('admission', 'link.lnk_admid', '=', 'admission.adm_id')
->join('outcome', 'link.lnk_otcid', '=', 'outcome.otc_id')
->where($matchThese)
->orWhere('outcome.otc_outcome', 'like', '%ICU%')
->orWhere('outcome.otc_outcome', 'like', '%I.C.U%')
->orWhere('outcome.otc_outcome', 'like', '%L3%')
->orWhere('outcome.otc_outcome', 'like', '%Level3%')
->orWhere('outcome.otc_outcome', 'like', '%Level 3%')
->orWhere('outcome.otc_outcome', 'like', '%Intensive Care Unit%')
->get();
$icuSize = sizeof($icu);
解决方案——谢谢@Mehravish Temkar
不同的查询,但相同的主体
$array_conditions = array('%ICU%', '%I.C.U%','%L3%','%Level3%','%Level 3%','%Intensive Care Unit%');
$step_down_icu = DB::table('link')
->join('daily_link', 'link.lnk_id', '=', 'daily_link.dlk_lnkid')
->join('admission', 'link.lnk_admid', '=', 'admission.adm_id')
->join('outcome', 'link.lnk_otcid', '=', 'outcome.otc_id')
->where('admission.adm_referraldate', '=', $td)
->where('outcome.otc_outcome', 'like', '%ICU%')
->Where(function ($query) use($array_conditions) {
for ($i = 0; $i < count($array_conditions); $i++){
$query->orwhere('outcome.otc_outcome', 'like', '%' . $array_conditions[$i] .'%');
}
})->get();
$step_down_icuSize = sizeof($step_down_icu);
$array_conditions=array(“%ICU%”、“%I.C.U%”、“%L3%”、“%Level3%”、“%Level3%”、“%Level3%”、“%重症监护病房%”);
$step\u down\u icu=DB::table('link')
->加入('daily_link'、'link.lnk_id'、'='、'daily_link.dlk_lnkid')
->join('acmission','link.lnk_admid','=','acmission.adm_id'))
->join('output','link.lnk_otcid','=','output.otc_id'))
->其中('acmission.adm_referraldate','=',$td)
->其中('outcome.otc_outcome','like','%ICU%'))
->其中(函数($query)使用($array\u条件){
对于($i=0;$iorwhere('outcome.otc_outcome','like','%.$array_conditions[$i].%');
}
})->get();
$step\u down\u icuSize=sizeof($step\u down\u icu);
只需将或where()
切换为where()
。查询生成器将使用和链接SQL子句
这应该起作用:
$array_conditions = array('%ICU%', '%I.C.U%','%L3%');
$matchThese = ['link.hos_id' => $hos_id, 'outcome.otc_otrdischargedate' => $td];
$icu = DB::table('link')
->join('demographic', 'link.lnk_dmgid', '=', 'demographic.dmg_id')
->join('admission', 'link.lnk_admid', '=', 'admission.adm_id')
->join('outcome', 'link.lnk_otcid', '=', 'outcome.otc_id')
->where($matchThese)
->whereIn('outcome.otc_outcome', 'like', $array_conditions)
->get();
$icuSize = sizeof($icu);
对于多个选项-['%ICU%'、'%I.C.U%'、'%L3%],您是否尝试使用where和pass数组而不是编写单独的或where条件?替换或where to where。使用where for AND和orWhere for ORum。。。明显的解决方案=面部和手掌。谢谢,我喜欢这个简单,但不幸的是它不起作用。@morne它没有显示所需的记录,或者有任何错误吗?@morne
$array_conditions = array('%ICU%', '%I.C.U%','%L3%');
$matchThese = ['link.hos_id' => $hos_id, 'outcome.otc_otrdischargedate' => $td];
$icu = DB::table('link')
->join('demographic', 'link.lnk_dmgid', '=', 'demographic.dmg_id')
->join('admission', 'link.lnk_admid', '=', 'admission.adm_id')
->join('outcome', 'link.lnk_otcid', '=', 'outcome.otc_id')
->where($matchThese)
->whereIn('outcome.otc_outcome', 'like', $array_conditions)
->get();
$icuSize = sizeof($icu);