我有
示例:
例如,我需要在10/03/2014和03/04/2015之间选择所有行的查询?问题是我分别有几天和几个月。我需要提取有关两个日期的所有content1和content2。
答案 0 :(得分:0)
使用Date
或Datetime
并免除其他原本会有的悲伤
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;
您可能会发现内置例程足够,例如间隔,而不必重写它们。 ;)
答案 1 :(得分:0)
试试这个:
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
答案 2 :(得分:0)
在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';
希望能帮到你