clear markdown compare help donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 497260 fiddles created (9488 in the last week).

create table p (id int, criterium decimal(18,2), init_year int, end_year int);
 hidden batch(es)


create table years(cyear int);
 hidden batch(es)


insert into years values(2010),(2011),(2012),(2013),(2014),(2015),(2016),(2017),(2018),(2019),(2020);
 hidden batch(es)


insert into p values (1, 93.0, 2018, 2020), (2, 50.0, 2015, 2017), (3, 74.5, 2010, 2012);
 hidden batch(es)


select id, cyear, (criterium / ((end_year - init_year) + 1.0)) as va from p join years on cyear >= init_year and cyear <= end_year order by id;
id cyear va
1 2018 31.000000
1 2019 31.000000
1 2020 31.000000
2 2017 16.666667
2 2015 16.666667
2 2016 16.666667
3 2010 24.833333
3 2011 24.833333
3 2012 24.833333
 hidden batch(es)