第 5 行出现错误 1370 (42000):对于例程 'datepart',用户 '@'localhost' 执行命令被拒绝

问题描述 投票:0回答:1

我一直在尝试为问题语句编写一个sql查询,但我一直面临这个错误

第 5 行出现错误 1370 (42000):拒绝用户执行命令 '@'localhost' 用于例程 'datepart'

我试过这个

WITH hours_worked as (
  

    SELECT
          emp_id,
             CASE 
           WHEN datepart(minute,TIMESTAMP) >= datepart(minute,lag(TIMESTAMP) OVER(PARTITION BY CAST(TIMESTAMP AS date),emp_id ORDER BY TIMESTAMP)) then datepart(hour,timestamp) - datepart(hour,lag(TIMESTAMP) OVER(PARTITION BY CAST(TIMESTAMP AS date),emp_id ORDER BY TIMESTAMP)) 
             ELSE datepart(hour,timestamp) - datepart(hour,lag(TIMESTAMP) OVER(PARTITION BY CAST(TIMESTAMP AS date),emp_id ORDER BY TIMESTAMP)) - 1
           END AS hours_worked
    FROM   attendance
    -- only weekends
    WHERE  datepart(weekday,TIMESTAMP) IN(7,1)
    )
    SELECT
       emp_id,
          SUM(hours_worked) as hours_worked
    FROM  hours_worked
    GROUP BY emp_id
    ORDER BY hours_worked desc
sql mysql
1个回答
0
投票

DATEPART() 不是 MySQL 中的内置函数。因此这是用户定义的函数。请参阅此函数定义和您当前的用户授予/权限。

© www.soinside.com 2019 - 2024. All rights reserved.