更改为Laravel语法后原始查询不起作用

更改为Laravel语法后原始查询不起作用,laravel,Laravel,我已经将这个查询转换成了Laravel语法,但不幸的是,vardump中没有输出,尽管它使用的是原始语法。我认为语法有问题: SQL语法(工作正常): Laravel语法(不工作): 在Laravel中,使用关系的更好方法如下: 为关系(一对一,一对多,…)定义模型和正确的函数,而不是使用Model::with()。您可以使用toSql()方法而不是get()来了解原始sql Laravel转换为的信息。然后您可以比较两个查询并解决问题。 $word_rec = DB::select( DB::

我已经将这个查询转换成了Laravel语法,但不幸的是,vardump中没有输出,尽管它使用的是原始语法。我认为语法有问题:

SQL语法(工作正常):

Laravel语法(不工作):


在Laravel中,使用关系的更好方法如下:

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

您可以使用toSql()方法而不是get()来了解原始sql Laravel转换为的信息。然后您可以比较两个查询并解决问题。
$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
")
 );
$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();