我有一个表USERS,其字段名为TIME_OF_CREATION。我想得到第一个记录和第二个记录之间经过的时间,然后是第三个记录,依此类推。我有这个SQL查询,但我在HQL中需要它。
WITH rows AS
(
SELECT *, ROW_NUMBER() OVER (ORDER BY TIME_OF_CREATION) AS rn
FROM users
)
SELECT DATEDIFF(second, mc.TIME_OF_CREATION, mp.TIME_OF_CREATION)
FROM rows mc
JOIN rows mp
ON mc.rn = mp.rn - 1
我试过这个:
with rows as (select u, row_number() over (order by u.timeOfCreation) as u.rn
from users ) select dateDiff(millisecond,u.timeOfCreation,u.timeOfCreation)
from rows u.mc join rows u.mp on u.mc.rn = u.mp.rn - 1
我得到了一个java.lang.IllegalArgumentException:要遍历的节点不能为null
有人可以帮助我获得HQL版本吗?我是HQL的初学者,所以任何帮助将不胜感激。 非常感谢提前