搜索

首页  >  问答  >  正文

将标题重写为:将Union查询转化为Laravel的方法

如何将此查询转换为Laravel?请帮忙

SELECT 
* 
FROM
(SELECT 
    xxx_details.xxx_id AS id,
    'xxx' AS restult_type,
    start_time,
    (
        MATCH (
            xxx_search_tags.xxx_search_tag
        ) AGAINST ('test') * 10
    ) + (
        MATCH (
            xxx_search_tags.xxx_search_tag
        ) AGAINST ('search') * 10
    ) AS relevance 
FROM
    xxx_details        
WHERE xxx_status = 'active'        
    AND MATCH (
        xxx_search_tags.xxx_search_tag
    ) AGAINST ('\'test search\'*' IN BOOLEAN MODE) 
    AND privacy_type = 'public' 
GROUP BY xxx_details.xxx_id 
UNION
SELECT 
    yyy_details.yyy_id AS id,
    'yyy' AS restult_type,
    start_time,
    (
        MATCH (
            yyy_details.yyy_name               
        ) AGAINST ('test') * 10
    ) + (
        MATCH (
            yyy_details.yyy_name              
        ) AGAINST ('search') * 10
    ) AS relevance 
FROM
    yyy_details 
    
WHERE yyy_status = 'active'
    AND MATCH (
        yyy_details.yyy_name,yyy_details.yyy_desc
    ) AGAINST ('\'test search\'*' IN BOOLEAN MODE) 
GROUP BY yyy_details.yyy_id)  
ORDER BY relevance DESC,
start_time ASC
P粉819937486P粉819937486443 天前526

全部回复(1)我来回复

  • P粉323050780

    P粉3230507802023-09-16 10:12:50

    尝试使用以下方法进行查询

    $results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = '$someVariable'") );

    回复
    0
  • 取消回复