当前位置: 首页 > news >正文

mysql 查询今天、昨天、本周、上周、本月、上月、本季度、上季度、本年、上一年、的数据

1、今天

select * from 表名 where to_days(时间字段名) = to_days(now())

2、昨天

select * from 表名 where to_days( now( ) ) - to_days( 时间字段名) <= 1

3、近7天

select * from 表名 where date_sub(curdate(), interval 7 day) <= date(时间字段名)

4、当前这周

select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())

5、上周

select name,submittime from enterprise where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())-1

6、近30天

select * from 表名 where date_sub(curdate(), interval 30 day) <= date(时间字段名)

7、本月

select * from 表名 where date_format( 时间字段名, '%y%m' ) = date_format( curdate( ) , '%y%m' )

8、上一月

select * from 表名 where period_diff( date_format( now( ) , '%y%m' ) , date_format( 时间字段名, '%y%m' ) ) =1

9、查询当前半年的数据 

select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now()

10、本季度

select * from `ht_invoice_information` where quarter(create_date)=quarter(now())

11、上季度

select * from `ht_invoice_information` where quarter(create_date)=quarter(date_sub(now(),interval 1 quarter))

12、本年

select * from `ht_invoice_information` where year(create_date)=year(now())

13、上年

select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year))

 

http://www.jsqmd.com/news/27888/

相关文章:

  • P10674 [MX-S1-T3] 电动力学 题解
  • 【UE引擎解构】- GamePlay篇 : 移动
  • 读后感一:《代码大全 2》—— 从 “写代码” 到 “做工程” 的思维跃迁 - A
  • Ai元人文:对“局限性”的反驳
  • 读后感二:《代码大全 2》—— 穿越技术迭代的 “软件开发说明书” - A
  • JDBC练习
  • 2-SAT学习笔记
  • 打造自己的 Claude Code:LangGraph + MCP 搭建一个极简的 AI 编码助手
  • CSP-S 2023-2024 分析
  • 专栏目录
  • 代码大全2 第四五章
  • 程序员修炼之道:从小工到专家读后感1
  • 代码大全2阅读1
  • 代码大全2阅读2
  • 软件工程学习日志2025.10.30
  • BOE(京东方)“百堂故宫传统文化公益课”暨2025照亮成长路收官 推动“科技+教育+文化”可持续发展
  • Java的深层逻辑与未来生态延伸
  • 软件工程学习日志2025.10.31
  • Java:从跨平台梦想到生态帝国的编程语言
  • [KaibaMath]1016 关于数列与其子数列下标不等关系的证明
  • MySQL解析JSON格式字段并取出部分值的方式
  • 【详细介绍】一种基于斜二进制的序列树上数据结构
  • drm分析
  • 8、认识for循环
  • node.js安装搭建
  • 102302156 李子贤 数据采集第二次作业
  • 2025年储能线束生产厂家排名:众晟强电子领先
  • SVD分解及其应用
  • 2025年工业线束生产厂家排名前十强,东莞众晟强电子引领行业创新
  • 完整教程:【C语言数据结构】第2章:线性表(1)--定义ADT