【问题标题】:How to convert mysql to laravel query builder [closed]如何将mysql转换为laravel查询构建器[关闭]
【发布时间】:2023-03-24 16:06:01
【问题描述】:

大家好,我在 mysql 中有这个原始查询,我需要翻译成 laravel 5.4 查询生成器

select * from pages where (phase_id, type) in (select max(phase_id),type from pages where phase_id<=2 and actived=1 group by type) and actived=1

我不知道如何在查询生成器中转换 clausule 与 2 列

有什么想法吗?

谢谢大家

【问题讨论】:

    标签: php mysql laravel laravel-5.4


    【解决方案1】:
    $results = DB::select(
        select * from pages where (phase_id, type) 
        in (
            select max(phase_id), type 
            from pages 
            where phase_id <= 2 
            and actived = 1 
            group by type
        ) 
        and actived = 1
    );
    

    【讨论】:

    • Thx @EddyTheDove ;) 存在另一种使用查询生成器的 ->whare() 或 whareIn() 方法的方式?
    • 如果你有一个 ID 数组,是的,你可以使用 whereIn。但它不需要那样的 SQL。你必须传递一个数组。
    猜你喜欢
    • 2021-12-11
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 2023-03-30
    • 1970-01-01
    • 2014-09-04
    • 2023-03-07
    相关资源
    最近更新 更多