Entiendo que podrías aplicar una suma condicional en función de la diferencia en días desde la fecha de inicio del rango, por ejemplo:
- Con
ac.invoice_datetime = cast('2019-08-26' as date) + INTERVAL '0 day'
verificamos que la fecha sea 2019-08-26
- Con
ac.invoice_datetime = cast('2019-08-26' as date) + INTERVAL '1 day'
verificamos que la fecha sea 2019-08-27
- Y así con cada fecha
Entonces podríamos hacer:
select rp.name,
sum(case when ac.invoice_datetime = cast('2019-08-26' as date) + INTERVAL '0 day' THEN ac.amount_untaxed ELSE 0 END) AS '2019-08-26',
sum(case when ac.invoice_datetime = cast('2019-08-26' as date) + INTERVAL '1 day' THEN ac.amount_untaxed ELSE 0 END) AS '2019-08-27',
sum(case when ac.invoice_datetime = cast('2019-08-26' as date) + INTERVAL '2 day' THEN ac.amount_untaxed ELSE 0 END) AS '2019-08-28',
sum(case when ac.invoice_datetime = cast('2019-08-26' as date) + INTERVAL '3 day' THEN ac.amount_untaxed ELSE 0 END) AS '2019-08-29',
sum(case when ac.invoice_datetime = cast('2019-08-26' as date) + INTERVAL '4 day' THEN ac.amount_untaxed ELSE 0 END) AS '2019-08-30',
sum(ac.amount_untaxed) as Total_venta
from account_invoice ac
join res_partner rp
on ac.partner_id=rp.id
where ac.invoice_datetime between '2019-08-26' and '2019-08-30'
and ac.state != 'cancel'
and ac.state != 'draft'
and rp.ruta='1'
or rp.id=7
group by rp.name;
Nota: asumo que en ac.invoice_datetime
solo tienes fecha, si tuvieras fecha + hora, deberías hacer un cast
as date
.