mysql日期与时间查询语句:查询当年、查询本年、查询当月、查询本周
mysql日期与时间查询语句:查询当年、查询本年、查询当月、查询本周
select sum(1) as years,
(select sum(1) from `表名` where date_format( 时间字段名, '%y%m' ) = date_format( curdate( ) , '%y%m')) as months,
(select sum(1) from `表名` where to_days(时间字段名) = to_days(now()))as days
from `表名` where year(regtime)=year(now())当天 select * from 表名 where to_days(时间字段名) = to_days(now());昨天 select * from 表名 where to_days( now( ) ) – to_days( 时间字段名) <= 1一周 select * from 表名 where date_sub(curdate(), interval 7 day) <= date(时间字段名)近30天 select * from 表名 where date_sub(curdate(), interval 30 day) <= date(时间字段名)本月 select * from 表名 where date_format( 时间字段名, ‘%y%m’ ) = date_format( curdate( ) , ‘%y%m’ )上一月 select * from 表名 where period_diff( date_format( now( ) , ‘%y%m’ ) , date_format( 时间字段名, ‘%y%m’ ) ) =1#查询本周记录
select * from ht_invoice_information where weekofyear(create_date)=weekofyear(now());
#查询上周记录
select * from ht_invoice_information where create_date>=date_add(now(),interval -(8 + weekday(now())) day) and create_date<=date_add(now(),interval -(1 + weekday(now())) day);--//或者
select * from `ht_invoice_information` where weekofyear(create_date)=weekofyear(date_sub(now(),interval 1 week));
#查询本月数据
select * from ht_invoice_information where month(create_date)=month(now()) and year(create_date)=year(now());
#查询上月数据
select * from ht_invoice_information where create_date<=last_day(date_add(now(),interval -1 month)) and create_date>=date_format(concat(extract(year_month from date_add(now(),interval -1 month)),’01′),’%y-%m-%d’);--//或者
select * from `ht_invoice_information` where month(create_date)=month(date_sub(now(),interval 1 month))
and year(create_date)=year(now());#查询本季度数据
select * from `ht_invoice_information` where quarter(create_date)=quarter(now());#查询上季度数据
select * from `ht_invoice_information` where quarter(create_date)=quarter(date_sub(now(),interval 1 quarter));#查询本年数据
select * from `ht_invoice_information` where year(create_date)=year(now());#查询上年数据
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));
mysql日期与时间查询语句:查询当年、查询本年、查询当月、查询本周相关推荐
- MySQL日期和时间函数的用法及使用举例
MySQL日期和时间函数的用法及使用举例 MySQL提供了用于处理日期和时间的相关函数.现对这些函数的功能及用法进行介绍并举例. 创建数据表emp并输入数据: create table emp(emp ...
- MySQL日期当前时间加月数
MySQL日期当前时间加月数 SQL 日期: 当我们处理日期时,最难的任务恐怕是确保所插入的日期的格式,与数据库中日期列的格式相匹配. 只要数据包含的只是日期部分,运行查询就不会出问题.但是,如果涉及 ...
- MySQL日期与时间函数
MySQL日期与时间函数 MySQL服务器中的三种时区设置: ①系统时区-保存在系统变量system_time_zone ②服务器时区-保存在全局系统变量global.time_zone ③每个客户端 ...
- mysql日期函数,时间函数大全
mysql获取当前时间,日期函数 获得当前日期函数 date(now()) 获得当前时间函数 time(now()) 获得当前日期+时间(date + time)函数:sysdate() ...
- mysql 创建时间类型,MySQL日期和时间类型
搜索热词 MysqL中存储日和和时间,使用日期和时间类型. 提供的包括YEAR.DATE.TIME.DATETIME和TIMESTAMP. YEAR 占用:1字节 取值范围:1901~2155 日期格 ...
- mysql 查询语句 过滤_MySQL全面瓦解7:查询的过滤条件
概述 在实际的业务场景应用中,我们经常要根据业务条件获取并筛选出我们的目标数据.这个过程我们称之为数据查询的过滤.而过滤过程使用的各种条件(比如日期时间.用户.状态)是我们获取精准数据的必要步骤, 这 ...
- mysql查询语句是什么意思_mysql子条件查询语句是什么意思?
mysql中,在一个表表达中可以调用另一个表表达式,这个被调用的表表达式叫做子查询(subquery)语句,也称作子选择(subselect)或内嵌选择(inner select).子查询的结果传递给 ...
- mysql中多表联合查询语句_mysql中的多表联合查询语句是什么
mysql中的多表联合查询语句是:[select 语句1 union [union 选项] select 语句2 union [union 选项] select 语句n].多表联合查询结果是将多个se ...
- mysql查询语句ppt_第4章数据库的查询和视图预览.ppt
4.3.2 创建视图 1.在SQL Developer中创建视图 启动SQL Developer,展开myorcl连接(需要输入SCOTT用户口令),右击"视图"节点选择" ...
最新文章
- OpenCV(基础补充)颜色空间HSV *args与**args(滑动条传参问题)
- Kotlin 协程:简单理解 runBlocking, launch ,withContext ,async,doAsync
- Android开发-将自定义View布局到Layout中并调用
- adb shell 修改文件名_从零开始学Linux运维|27.Shell编程(函数与参数的传递)
- chrome console 调试xpath
- OpenCV3.1.0+VS2015开发环境配置
- IOS 多层级路由导航控制器 NavigationControoller 实现路由切换
- C++之文件操作探究(四):读文件——二进制文件
- C语言 signal
- BZOJ 1013 球形空间产生器
- 谈谈WCF中的Data Contract(2):WCF Data Contract对Generic的支持
- 随机信号分析基础——例题篇(例题3.4)
- 米家扫地机器人是石头代工_石头扫地机器人T4全面评测 支持软件虚拟墙,清扫更高效...
- 一文了解单线激光扫描系统的标定与成像原理
- No buffer space available终极解决办法
- Cloudera Manager安装教程
- 端口映射和端口转发区别是什么
- 客户端开发 Windows驱动开发(1)SDK WDK DDK WDM的关系
- notepad++ 同时搜索多个关键字
- 高新技术企业补助政策