Here is a bit of data from my table. The field names are self explanitory, except the last field is the totalPrice for the whole booking.
bookingnum firstdayout itemnum pretaxtotalprice
1323 01/06/2007 104 $34.50
1323 01/06/2007 149 $34.50
1323 01/06/2007 208 $34.50
1323 01/06/2007 25 $34.50
1323 01/06/2007 38 $34.50
1321 01/06/2007 133 $43.86
1322 01/06/2007 214 $51.80
1322 01/06/2007 252 $51.80
1322 01/06/2007 290 $51.80
1322 01/06/2007 0 $51.80
1322 01/06/2007 298 $51.80
1323 01/06/2007 219 $34.50
1184 01/10/2007 4 $145.00
1184 01/10/2007 41 $145.00
1184 01/10/2007 212 $145.00
1184 01/10/2007 218 $145.00
1184 01/10/2007 262 $145.00
1184 01/10/2007 235 $145.00
1184 01/10/2007 253 $145.00
1184 01/10/2007 50 $145.00
1325 01/10/2007 62 $52.62
1326 01/11/2007 208 $27.00
1326 01/11/2007 325 $27.00
1326 01/11/2007 150 $27.00
I have a query now that returns the one distinct booking (all i need for this query is the day out and the pretaxtotalprice).
From "SELECT DISTINCT bookingnum, firstdayout, pretaxtotalprice, rentalstatus FROM tblbooking WHERE firstdayout between #1/1/2007# and date();"
bookingnum firstdayout pretaxtotalprice rentalstatus
1321 01/06/2007 $43.86 0
1322 01/06/2007 $51.80 1
1323 01/06/2007 $34.50 2
1184 01/10/2007 $145.00 0
1325 01/10/2007 $52.62 0
1326 01/11/2007 $27.00 0
But, I want to get the totals for each day.
So i use
SELECT DISTINCT firstdayout, sum(pretaxtotalprice)
FROM [SELECT DISTINCT bookingnum, firstdayout, pretaxtotalprice FROM tblbooking WHERE firstdayout between #1/1/2007# and date()]
GROUP BY firstdayout;
And it seems to work correctly. Is this the right way to do this?
Also - how can I filter the results (with an If statement?) to seperate the values based on the rentalstatus value: RentalStatus=0 is confirmed, =1 is quote and =2 is deleted. So i would like to get the daily pretaxtotalprice for each type.
Start Free Trial