我正在向 IBM DB2 服务器编写以下查询:
SELECT
EMPNO,
YEAR(CURRENT TIMESTAMP - BIRTHDATE) AS AGE,
DENSE_RANK() OVER(ORDER BY YEAR(CURRENT TIMESTAMP - BIRTHDATE) ASC) AS RANK
FROM
DANDY.EMPLOYEE;
它有效,但看起来很难看,因为我正在重复表达:
YEAR(CURRENT TIMESTAMP - BIRTHDATE)
但是这样写是行不通的:
DENSE_RANK() OVER(ORDER BY AGE ASC) AS RANK
如何让它变得更好?