There is a table reservations in mysql database in the below format.
id | customer_id | user_id | date_booked
1 | 1 | 1 | 2012-11-5
I want to get the count of customers for a particular User. so I wrote query
select count(*), user_id, customer_id,date_booked from reservations where user_id=1 group by customer_id
This fetches results in desired way. But date_booked , I get the first value recorded. i.e., If there are 4 records for a customer with id 2 , It fetches 1st record’s date_booked value. I want the latest value , So I improved the query like below
select count(*), user_id, customer_id,max(date_booked) from reservations where user_id=1 group by customer_id
This fetches highest date recorded. This is still not the result set I want to fetch. I want the latest date but that should be less that current date (today).
Is there a way to write condition like this
max(date_booked)<date(now())
I want to fetch max date but less than today. I want to achieve this in CakePHP. If someone can help with Query I can write it cakePHP format.
Please improve the question if necessary.
1 Answer