This is also one example to find a leap year with several restrictions.
select year_n from the_years select distinct month_n from the_months,the_years where year_n=$P{Year} (select distinct day_n from the_days,the_months where $P{Month} IN('Jan','Mar','May','Jul','Aug','Oct','Dec') limit 31) UNION ALL (select distinct day_n from the_days,the_months where $P{Month} IN('Apr','Jun','Sep','Nov') limit 30) UNION ALL (select distinct day_n from the_days,the_years,the_months where $P{Month}='Feb' and mod($P{Year},4)!=0 or mod($P{Year},100)=0 or mod($P{Year},400)=0 limit 28) UNION ALL (select distinct day_n from the_days,the_years,the_months where $P{Month}='Feb' and mod($P{Year},4)=0 and mod($P{Year},100)!=0 or mod($P{Year},400)=0 limit 29)
Ansul gupta
source share