在laravel中使用join进行查询

时间:2017-05-11 12:24:46

标签: php mysql laravel

我需要在laravel中编写此查询,但我不知道如何编写它

Select RANKED.rankTotal*MATCHED.Popularity score
     , urlID  
  from 
     ( SELECT sum(rank) as rankTotal
            , urlID 
         FROM searchengine.indexer
        where keyword IN("there","is") 
        group 
           by urlID 
     ) RANKED
     , 
     ( Select ID
            , Popularity 
          From searchengine.visitedpages 
         where document LIKE '%there is%'
     ) MATCHED
 where RANKED.urlID = MATCHED.ID ;

1 个答案:

答案 0 :(得分:-1)

看看这是否适合你。

$query = \DB::raw("Select RANKED.rankTotal*MATCHED.Popularity as score, urlID  from (SELECT  
                   sum(rank) as rankTotal,urlID 
                   FROM searchengine.indexer
                   where   (keyword=? or keyword=?) group by urlID ) as RANKED, 
                   (Select ID, Popularity 
                   From searchengine.visitedpages where document LIKE ?)  as MATCHED
                   where RANKED.urlID =MATCHED.ID ;");

$results = \DB::select($query, ['there', 'is', '%there is%']);