如果我有几个单独的日期行,如何从 MySQL 中 select 数据行?

How to select data rows from MySQL if i have few date rows separately?

我有

  1. 天栏,
  2. 月栏,
  3. 年份列,
  4. content1 列,
  5. content2 列,

示例:

  1. 第 12 天
  2. 第 6 个月
  3. 2015 年

例如,我需要什么查询 select 10/03/2014 和 03/04/2015 之间的所有行?问题是我分别有几天和一个月。我需要提取关于两个日期的所有 content1 和 content2。

使用 DateDatetime 让自己远离悲伤

drop table theGuy;

create table theGuy
(
    id int not null auto_increment primary key,
    fullName varchar(60) not null,
    birthDate date not null
);

insert theGuy (fullName,birthDate) values ('Kim Smithers','2002-3-1'),('John Doe','2014-4-5');

select * from theGuy where birthDate>='2000-1-1' and birthDate<='2007-12-31';

select * from theGuy where birthDate between '2000-1-1' and '2007-12-31';


select *,birthDate+interval 45 DAY as BirthCertAvail from theGuy;

select *,datediff(curdate(),birthDate) as DaysAlive from theGuy;

您可能会发现内置例程足够了,例如间隔,而无需重写它们。 ;)

试试这个:

SELECT 
    *
FROM
    my_table
HAVING
    CONVERT(CONCAT(year, '-', month, '-', day), DATE) BETWEEN '2014-10-03' AND '2015-03-04';(Year||' '||Day||' '||Month, 'YYYY DD MM') BETWEEN date1 AND date2

在 MySQL 中,此查询将有效

SELECT content1,content2 FROM the_table 
WHERE STR_TO_DATE(CONCAT(month, '/', day, '/', year), '%m/%d/%Y') BETWEEN '10/03/2014' AND '03/04/2015';

希望对你有所帮助