group by month depend on last date in month

I want to make a query to group date by month depend on the last date.

in my table:

july

2015-07-02

2015-07-03 

august

2015-08-04

this is my query:

   SELECT DISTINCT Visit_Date FROM tr_visit 
   JOIN tm_child ON tm_child.Child_ID = tr_visit.Child_ID 
   WHERE tr_visit.Child_ID='CH001'
   GROUP BY YEAR(tr_visit.Visit_Date), MONTH(tr_visit.Visit_Date) DESC

My result is:

2015-07-02
 and 2015-08-04

How can I select the last visit in july so the result become:

2015-07-03 (last visit in july)
 and 2015-08-04 (last visit in august)

Upvotes: 1

Views: 70

Answers (1)

Fabricator
Fabricator

Reputation: 12782

like this?

select max(visit_date)
from tr_visit
group by year(visit_date), month(visit_date);

Upvotes: 1

Related Questions