Home  >  Article  >  Database  >  sql 统计本周,本月,下周,下月sql语句

sql 统计本周,本月,下周,下月sql语句

WBOY
WBOYOriginal
2016-06-07 17:47:121919browse

//本款sql 语句可以查询,本周,本月,下周,下月生日的相关数据

sql 统计本周,本月,下周,下月sql语句
/*
表结构

Student(S#,Sname,Sage,Ssex) --S# 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别

保存一些数据

insert into Student values('01' , N'wwww.111cn.net' , '1990-01-01' , N'男')
insert into Student values('02' , N'钱电' , '1990-12-21' , N'男')
insert into Student values('03' , N'孙风' , '1990-05-20' , N'男')
insert into Student values('04' , N'李云' , '1990-08-06' , N'男')
insert into Student values('05' , N'周梅' , '1991-12-01' , N'女')

 

查询本周数据sql语句

select * from student where datediff(week,datename(yy,getdate()) + right(convert(varchar(10),sage,120),6),getdate()) = 0

--48、查询下周数据sql语句

select * from student where datediff(week,datename(yy,getdate()) + right(convert(varchar(10),sage,120),6),getdate()) = -1

--49、查询本月数据sql语句

select * from student where datediff(mm,datename(yy,getdate()) + right(convert(varchar(10),sage,120),6),getdate()) = 0

--50、查询下月数据sql语句

select * from student where datediff(mm,datename(yy,getdate()) + right(convert(varchar(10),sage,120),6),getdate()) = -1

drop table  Student,Course,Teacher,SC
*/

//本款sql 语句可以查询,本周,本月,下周,下月生日的相关数据

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn