简体   繁体   中英

MySQL distinct and left, right

I have a table with day column like this:

2011-04-28, 2011-04-29 ...
day           count  name surname
2011-04-28    8       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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM