SQL pour summary financier dans le SI

De Société Coopérative d'Aménagement Numérique Icaunaise
Aller à la navigation Aller à la recherche
select valid_from, valid_until, dbegin_may, dend_may,
    (dend_may - dbegin_may + 1) as nb_days_may,
    value_day, nb_days,
    value_day * (dend_may - dbegin_may + 1) as value_may from
    (select
    valid_from, valid_until,
    greatest(valid_from, '2016-05-01') as dbegin_may,
    least(valid_until, '2016-05-31') as dend_may,
    price,
    price / (valid_until - valid_from) as value_day,
    valid_until - valid_from as nb_days
    from invoices_elts
    where valid_until >= '2016-05-01' and valid_from <= '2016-05-30')
    as may;