improve the report sql query

This commit is contained in:
Ruidy 2024-02-28 17:56:23 +01:00
parent 68df2f06a2
commit ea039dc428
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

View file

@ -118,14 +118,11 @@ func (bs Service) BuildReport(period string, month, year int) *Report {
}
bs.db.Raw(`
select id, customer_name, "from", "to", platform, total, platform_fees
from (select sum(price*quantity) as total, booking_id
from bookings
join items on bookings.id = items.booking_id
where "from" between ? and ?
group by booking_id) as sbi,
(select * from bookings) as b
where sbi.booking_id = b.id;
select bookings.id, customer_name, "from", "to", platform, sum(price * quantity) as total, platform_fees
from bookings
join items on bookings.id = items.booking_id
where "from" between ? and ?
group by bookings.id;
`,
startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).
Scan(&lines)