Hi,
i have a car booking system that stores the startdate and the enddate of a booking as well as car/customer details.
i want to produce an efficiency report that shows how many days the car is booked per month.
i am having trouble getting the results - the column that sums the days between the booking start and end date is producing all sorts of results
so far i have
i have a car booking system that stores the startdate and the enddate of a booking as well as car/customer details.
i want to produce an efficiency report that shows how many days the car is booked per month.
i am having trouble getting the results - the column that sums the days between the booking start and end date is producing all sorts of results
so far i have
Code:
SELECT CC.reg, CBB.bookst, CBB.bookend, CC.carid, CBB.courtcarbookid,tran.trandesc, CC.model, concat(sum(datediff(cbb.bookend,cbb.bookst))) as days, month(cbb.bookst)
as month
FROM courtcar AS CC
LEFT JOIN (SELECT CB.bookst, CB.bookend, CB.carid, CB.courtcarbookid, CB.cusid
FROM courtcarbook AS CB WHERE (cb.bookst BETWEEN '20070101' AND '20071231')
OR (cb.bookend BETWEEN '20070101' AND '20071231')
OR (cb.bookst <= '20070101') AND (cb.bookend >= '20071231')) AS CBB
ON CC.carid = CBB.carid LEFT JOIN tran ON CC.tranid = tran.tranid
LEFT JOIN cus ON cus.cusid = CBB.cusid
WHERE display = 0
GROUP BY CC.carid, month(cbb.bookst)
ORDER BY CC.carid ASC, CC.makeid ASC, CBB.bookst ASC