【mysql】查询某一年 某一月 某一天的数据
作者:admin 日期:2017-07-05
查询某一年 某一月 某一天的数据(可组合)
select * fromymt where date_format(inDate,'%Y-%m-%d')='2016-10-10';
(inDate为表中列名)
MySQL查询一天,查询一周,查询一个月内的数据
查询一天
select * from ymt where DATE(inDate)=CURDATE();
select * from ymt where to_days(inDate)=to_days(now());
查询一周:
select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= DATE(column_time);
查询一个月:
select * fromtable where DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= DATE(column_time);
查询选择所有 date_col 值在最后 30 天内的记录。
Select something FROM tbl_name
Where TO_DAYS(NOW()) -TO_DAYS(date_col) <= 30;
DATE_ADD(date,INTERVALexpr type)
DATE_SUB(date,INTERVALexpr type)
select * from market_orders where createdate>='2010-03-01 00:00:00' and createdate<'2016-03-02 00:00:00'
上面的语句返回的是这个时间段内的所有行
select count(*) from market_orders where createdate>='2010-03-01 00:00:00' and createdate<'2016-03-02 00:00:00'
这条语句返回的是这个时间段内有几条数据
时间可以不加时分秒,只有年月日也行。
下一篇: 白河子成绩查询系统php版本1.0(兼容移动端访问)
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志: