【问题标题】:Laravel SQL General error: 4015 Window function is allowed only in SELECT list and ORDER BY clauseLaravel SQL 一般错误:4015 窗口函数只允许在 SELECT 列表和 ORDER BY 子句中使用
【发布时间】:2022-06-14 21:04:00
【问题描述】:

我正在尝试在 Laravel 中获取下一行和上一行 id,但它不会让我这样做而不会出现此错误:

SQLSTATE[HY000]: 一般错误: 4015 Window function is allowed only 在 SELECT 列表和 ORDER BY 子句中(SQL:SELECT OrderID、EmployeeID、 LEAD(OrderID,1) OVER ( ORDER BY OrderID ) nextID, lag(OrderID,1) OVER ( ORDER BY OrderID ) 以前的 FROM 订单组 BY OrderID, EmployeeID, nextID, previous )

这是正在处理的代码

$order = DB::select(DB::raw(" 
    SELECT
        OrderID, 
        EmployeeID,
        LEAD(OrderID,1) OVER (
            ORDER BY OrderID
        ) nextID,
        lag(OrderID,1) OVER (
            ORDER BY OrderID
        ) previous
        
    FROM 
        orders

    group BY
        OrderID,
        EmployeeID,
        nextID,
        previous
    "))->orderby('OrderID', 'EmployeeID', 'nextID', 'previous')->get();

【问题讨论】:

  • 您是否尝试在不使用 GROUP BY 的情况下执行查询?

标签: sql laravel laravel-9


猜你喜欢
  • 1970-01-01
  • 2012-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-22
相关资源
最近更新 更多