From ea039dc428fc0f399bff492bd2e2308b060bfa7e Mon Sep 17 00:00:00 2001 From: Ruidy Date: Wed, 28 Feb 2024 17:56:23 +0100 Subject: [PATCH] improve the report sql query --- internal/booking/service.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/booking/service.go b/internal/booking/service.go index dbabbcf..10d72c7 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -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)