简体   繁体   English

MySQL 左右分明

[英]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. DISTINCT 只能应用于 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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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