I have a table with day column like this:
2011-04-28, 2011-04-29 ...
day count name surname
2011-04-28 8开发者_如何学Go titi tutu
2011-04-28 12 tutu toto
2011-04-27 2 tutu toto
2011-03-12 10 tutu toto
I can obtain distinct day but not only month and year.
select distinct(day) from Table where day between "2011-03-01" and "2011-04-28";
I want only distinct month and year.
Can you help me?
Thanks
select DISTINCT EXTRACT(YEAR_MONTH FROM `day`) as yearmonth
from Table
where day between '2011-03-01' and '2011-04-28';
DISTINCT may be applied only to the whole row in mysql. So, you need to extract what you need first from the date.
select distinct(EXTRACT YEAR_MONTH FROM `day`) from Table
where day between "2011-03-01" and "2011-04-28";
精彩评论