开发者

MySQL distinct and left, right

开发者 https://www.devze.com 2023-03-01 09:43 出处:网络
I have a table with day column like this: 2011-04-28, 2011-04-29 ... daycountname surname 2011-04-288开发者_如何学Gotiti tutu

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";
0

精彩评论

暂无评论...
验证码 换一张
取 消