首页 > 解决方案 > 将原始数据库查询转换为 Laravel 查询构建器

问题描述

我在将此原始查询转换为 Laravel 查询生成器时遇到了一些问题:

\DB::select("
        select *
        from (
            select *,
            ROW_NUMBER() OVER(ORDER BY id) AS rownum
            from (
                select * from templates
                where industry_id = 2 and (palette_id = 1 OR palette_id = 2)
            ) as t1
        ) as t2
        WHERE (t2.rownum - 1) % 2 = floor(((t2.rownum - 1) / 2)) % 2
        ORDER BY t2.id"
    );

我尝试在这里转换它,但出现了一些错误:http ://cryptic-peak-77605.herokuapp.com/

任何帮助表示赞赏。

标签: mysqlsqllaravel

解决方案


推荐阅读