【发布时间】:2013-10-21 08:03:32
【问题描述】:
对于包含 int 字段日期、月份和年份的数据库表,查询大于指定日期的行的最佳方法是什么?
【问题讨论】:
-
什么数据库实现(即Oracle、MySQL?)
对于包含 int 字段日期、月份和年份的数据库表,查询大于指定日期的行的最佳方法是什么?
【问题讨论】:
你可以这样做:
select dateofbirth from customer Where DateofBirth BETWEEN date('1004-01-01') AND date('1980-12-31');
select dateofbirth from customer where date(dateofbirth)>date('1980-12-01');
select * from customer where date(dateofbirth) < date('now','-30 years');
【讨论】:
通过简单的算术,您可以做出如下选择:
SELECT * FROM t WHERE year*10000+month*100+day>20131021;
【讨论】: