0

我已将此查询转换为 Laravel 语法,但不幸的是,vardump 中没有输出,尽管它以原始语法工作。我认为语法有问题:

SQL 语法(工作正常):

$word_rec = DB::select( DB::raw("
select distinct
pa.alias 
,p.name_full_formatted
, o.ordered_as_mnemonic 
, c3.event_tag    RET
, c2.event_tag   QTY
, c1.event_tag   CHK

from

CLINICAL_EVENT   C1   
, orders  o
, encounter  e
, person  p
, person_alias  pa
, CLINICAL_EVENT   C2  
, CLINICAL_EVENT   C3  


 where e.person_id = o.person_id
 and p.person_id = o.person_id
 and pa.person_id = p.person_id
and pa.person_alias_type_cd = 10
 and o.order_id = c2.order_id and c2.task_assay_cd = 2622303965
 and o.order_id = c3.order_id and c3.task_assay_cd = 2622303953
 and c1.encntr_id = o.encntr_id and c1.task_assay_cd = 2622303989
")
 );

Laravel 语法(不工作):

$word_rec = DB::table('orders as o')
    ->join('encounter as e', 'e.person_id', '=', 'o.person_id')
    ->join('person as p', 'p.person_id', '=', 'o.person_id')
    ->join('person_alias as pa', 'pa.person_id', '=', 'p.person_id')
    ->join('clinical_event as c2', 'c2.order_id', '=', 'o.order_id')
    ->join('clinical_event as c3', 'c3.order_id', '=', 'o.order_id')
    ->join('clinical_event as c1', 'c1.encntr_id', '=', 'o.encntr_id')
    ->where('pa.person_alias_type_cd' , '=' , 10)
    ->where('c2.task_assay_cd' , '=' , 2622303965)
    ->where('c3.task_assay_cd' , '=', 2622303953)
    ->get();
4

1 回答 1

0

在 Laravel 中更好地使用关系,如下所示:https ://laravel.com/docs/6.x/eloquent-relationships 。

为关系(一对一、一对多、...)定义模型和更正函数,而不是使用 Model::with()。

于 2019-11-14T13:31:37.573 回答