首页 > 解决方案 > mariadb Lead() 函数不接受今天的日期作为默认参数

问题描述

我正在尝试在 mysql 中使用 Lead/Lag 函数。在超前和滞后功能中,可以选择对最后一个不存在的行使用默认值。请参阅下面的文档

LEAD(expr [, N[, default]]) [null_treatment] over_clause

在上面的默认值中,我想使用curdate()函数,但它给出了错误

例如我的查询如下

SELECT
  AdmissionNo,         
  PatientShiftDate,
  timestampdiff(DAY, PatientShiftDate,
      lead(PatientShiftDate, 1 , NOW()     )  
         over ( order by IPDBedAllocationNo)  )  as NoofStay 
FROM
  PatientBedShift

它给出了错误

#42000You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' curdate()      )  over ( order by IPDBedAllocationNo)  )  as NoofStay  FROM...' at line 5

我想计算患者在每个房间停留的天数。它返回 null 而不是它应该使用 curdate()、now() 或 current_timestamp() 函数,这样我就可以获得患者在单个查询中停留的正确天数。

标签: mariadblead

解决方案


推荐阅读