SQL Server displays charts based on time statistics

Source: Internet
Author: User
Tags getdate

  --year  SelectM as [Date],sum( Case  when DatePart(Month, Createdatetime)=M Then 1 Else 0 End) as [Count]      from [dbo]. Crmcustomer C, (Select 1mUnion  All Select 2      Union  All Select 3     Union  All Select 4    Union  All Select 5     Union  All Select 6      Union  All Select 7     Union  All Select 8      Union  All Select 9      Union  All Select Ten      Union  All Select  One      Union  All Select  A) AAwhere  '2018'=  Year(Createdatetime)Group  bym; --this month    Select DATEPART( Day, Createdatetime) as [Date],COUNT(ID) as [Count]  from [dbo]. CrmcustomerWHERE   DATEPART(MM, Createdatetime)= DATEPART(MM,GETDATE()) and DATEPART(YY, Createdatetime)= DATEPART(YY,GETDATE())     Group  by DATEPART( Day, Createdatetime)
--this week Select Convert(nvarchar(Ten), Createdatetime, -) as [Date],COUNT(ID) as [Count] from [dbo]. Crmcustomerwhere DateDiff(Week, Createdatetime,getdate())=0 Group by Convert(nvarchar(Ten), Createdatetime, -)

SQL Server displays charts based on time statistics

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.