我需要使用mysql查询检索最近100年,而不使用存储函数或临时表。
预期结果:
答案 0 :(得分:2)
挑战在于产生整数。一旦你有100个整数,其余的很容易。这是一种方式:
select year(now()) - (d1.n*10 + d2.n) as yr
from (select 1 as n union all select 2 union all select 3 union all select 4 union all select 5 union all
select 6 union all select 7 union all select 8 union all select 9 union all select 0
) d1 cross join
(select 1 as n union all select 2 union all select 3 union all select 4 union all select 5 union all
select 6 union all select 7 union all select 8 union all select 9 union all select 0
) d2
order by yr;