MySQL查询本周、上周、本月、上个月份数据的sql代码(转)
感谢:http://www.jb51.net/article/32277.htm
------------------------------------------------------------------------------
MySQL查询的方式很多,下面为您介绍的MySQL查询实现的是查询本周、上周、本月、上个月份的数据,如果您对MySQL查询方面感兴趣的话,不妨一看
查询当前这周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now());
查询上周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1;
查询当前月份的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m')
查询距离当前现在6个月的数据
select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();
查询上个月的数据
select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')
select * from `user` where DATE_FORMAT(pudate,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') ;
select * from user where WEEKOFYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d')) = WEEKOFYEAR(now())
select *
from user
where MONTH(FROM_UNIXTIME(pudate,'%y-%m-%d')) = MONTH(now())
select *
from [user]
where YEAR(FROM_UNIXTIME(pudate,'%y-%m-%d')) = YEAR(now())
and MONTH(FROM_UNIXTIME(pudate,'%y-%m-%d')) = MONTH(now())
select *
from [user]
where pudate between 上月最后一天
and 下月第一天
MySQL查询本周、上周、本月、上个月份数据的sql代码(转)的更多相关文章
- MySQL查询今天/昨天/本周、上周、本月、上个月份数据的sql代码
MySQL查询本周.上周.本月.上个月份数据的sql代码 作者: 字体:[增加 减小] 类型:转载 时间:2012-11-29我要评论 MySQL查询的方式很多,下面为您介绍的MySQL查询实现的是查 ...
- MySQL查询今天/本周/上周/本月/上个月份的数据
MySQL查询的方式很多,下面为您介绍的MySQL查询实现的是查询本周.上周.本月.上个月份的数据,如果您对MySQL查询方面感兴趣的话,不妨一看. 查询当前今天的数据 SELECT name,sub ...
- MySQL查询本周、上周、本月、上个月份数据的sql代码
查询当前这周的数据 SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) ...
- MySQL查询本周、上周、本月、上个月份数据的sql脚本
2018-11-13 查询今天的数据 select * from 表名 where to_days(时间字段名) = to_days(now()); 查询昨天的数据 SELECT * FROM 表名 ...
- 用php获取本周,上周,本月,上月,本季度日期的代码
echo date("Ymd",strtotime("now")), "\n"; echo date("Ymd",str ...
- [moka同学笔记]php 获取时间(今天,昨天,三天内,本周,上周,本月,三年内,半年内,一年内,三年内)
<?php /** * php 获取时间(今天,昨天,三天内,本周,上周,本月,三年内,半年内,一年内,三年内) * * author:ihelloworld2010@gmail.com * d ...
- MySQL 查询某个数据库中所有包含数据记录的表名
MySQL 查询某个数据库中所有包含数据记录的表名 有时根据实际应用需要,需要对数据进行备份. 如果一个数据库中有很多数据表,但是只想备份包含数据记录的那些表数据(空表不做数据备份). 如果通过如下S ...
- sql server 查询本周、本月所有天数的数据
查询本月所有的天数: --本月所有的天数 ),) day from (),,)+'-01' day) t1, ( ) t2 ),) ),,)+'%' 查询本周所有的天数: ),,),) ),,),) ...
- mysql查询本周、月、季度、年
#查询本周记录 select * from product_process where WEEKOFYEAR(update_time)=WEEKOFYEAR(now()); #查询本月数据 selec ...
随机推荐
- Java Concurrency - Callable & Future
One of the advantages of the Executor framework is that you can run concurrent tasks that return a r ...
- python学习day4--python基础--字典
字典的常用操作: #字典天然去重,key唯一,如果key相同,只能打印出一个 id_db={ 220456789852963741:{ 'name':"alex", 'age':3 ...
- oracle储存过程,job,视图,触发器(记性不好,写个例子自己记)
存储过程 create or replace procedure TestPro(Descerr out varchar2 ) is begin select * from test; excepti ...
- XMPP登录应用
一.导入框架 1.XMMP框架,写入头文件,设置XMPPStreamDelegate代理,定义 XMPPStream *_xmppStream; 2.libresolv.dylib 3.libxml2 ...
- java新手笔记34 连接数据库
1.JdbcUtil package com.yfs.javase.jdbc; import java.sql.Connection; import java.sql.DriverManager; i ...
- easyui知识累计.递增.
(001) 偶然发现 easyui 1.4.4 版本以下在使用easyloader时的一个bug(声明:只有在使用easyloader加载模块时有此问题) : (只测试过1.4.2, 1.4.3, 1 ...
- Linux 通过 shell 脚本修改密码
交互方式修改密码 1. ssh 远程到主机: 2. 切换到root账号: [一般都是切换到root进行密码修改,如果普通用户修改自己的密码,要输入原密码,然后新密码要满足复杂度才OK]: 3. pas ...
- javascript之高级函数应用思想
1.级联函数:应用对象方法调用的连写 function A(){ this.a = ''; this.b = ''; this.c = ''; } //改造一下 A.prototype = { A.p ...
- Setfocus - IE 需要使用setTimeout
setTimeout(function () { $('#controlid').focus(); }, 100); document.getElementById('filterPopupInput ...
- 解决FPDF报错:FPDF error: Not a JPEG file / FPDF error: Not a PNG file
最近有个项目需要用到FPDF,但是输出的时候报错: FPDF error: Not a JPEG file: http://***/data/attachment/forum/201603/19/10 ...