当我尝试运行此查询时,它失败了:
SELECT COUNT(id), (CURRENT_DATE - birth_dt) / 365 AS age
FROM players
ORDER BY age
GROUP BY age
有许多解决方法,这样的工作正常:
WITH ages (id, age) as
(SELECT id, (CURRENT_DATE - birth_dt) / 365 AS age
FROM players )
SELECT COUNT(id), age
FROM ages
ORDER BY age
GROUP BY age
但这对于这样一个微不足道的问题来说似乎有些过分。有没有直截了当(单select
)方式?
由于