SQL Statistics this week, this month, next week, the next month SQL statement

Source: Internet
Author: User
Keywords Network programming Database synthesis
Tags .net data name net network network programming programming save

SQL Statistics this week, this month, next week, the next month SQL statement
/*
Table structure

Student (s#,sname,sage,ssex)--s# student number, sname student name, Sage birth date, ssex student gender save some data

INSERT into Student values (' ', n ' wwww.111cn.net ', ' 1990-01-01 ', n ' Men ')
INSERT into Student values (' ", N ' money electricity ', ' 1990-12-21 ', n ' Men ')
INSERT into Student values (' ", N ' Sun Wind ', ' 1990-05-20 ', n ' Male ')
INSERT into Student values (' ', n ' li ', ' 1990-08-06 ', n ' Men ')
INSERT into Student values (' ', n ' Zhou Mei ', ' 1991-12-01 ', n ' Women ')

Query this week's data SQL statement

SELECT * FROM student where DateDiff (Week,datename (Yy,getdate ()) + right (CONVERT (varchar (), sage,120), 6), GETDATE ()) = 0--48, query next week data SQL statement

SELECT * FROM student where DateDiff (Week,datename (Yy,getdate ()) + right (CONVERT (varchar (), sage,120), 6), GETDATE ()) = -1--49, query this month's data SQL statements

SELECT * FROM student where DateDiff (Mm,datename (Yy,getdate ()) + right (CONVERT (varchar (), sage,120), 6), getdate () = 0- -50, query the next month data SQL statements

SELECT * FROM student where DateDiff (Mm,datename (Yy,getdate ()) + right (CONVERT (varchar (), sage,120), 6), getdate () =-1

drop table STUDENT,COURSE,TEACHER,SC
*/
This section of the SQL statement can be queried, this week, this month, next week, the next month birthday related data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.