Statistics for commonly used SQL
To count commonly used SQL statements:
All data for Today:SELECT *From table namewhere DateDiff (dd,datetime Type field, GETDATE ()) =0All data for yesterday:SELECT *From table namewhere DateDiff (dd,datetime Type field, GETDATE ()) =1All data in 7 days:SELECT *From table namewhere DateDiff (dd,datetime Type field, GETDATE ()) <=7All data in 30 days:SELECT *From table namewhere DateDiff (dd,datetime Type field, GETDATE ()) <=30All data for this month:SELECT *From table namewhere DateDiff (mm,datetime Type field, GETDATE ()) =0All data for this year:SELECT *From table namewhere DateDiff (yy,datetime Type field, GETDATE ()) =0Query today is the first day of this year:SelectDatePart (dayofyear,getdate ()) query today is the day of the month:1.SelectDATEPART (DD, getDate ())2.SelectDay (GetDate ()) Query Week 1st of the week is how much (note: The specified date cannot be Sunday, if it is Sunday will be calculated to the next Monday go.) So if it's Sunday to lose a day) SELECT DATEADD (Wk,datediff (wk,0,getdate ()),0) query yesterday's date:Select CONVERT (Char,dateadd (dd,-1,getdate ()),111)//111 is the style number, (100-114)Query first day of the month Date: Select DATEADD (mm, DATEDIFF (mm,0,getdate ()),0)AsFirstDay query last day of the month Date: Select DateAdd (ms,-3,dateadd (mm, DATEDIFF (M,0,getdate ()) +1,0))As Lastday//Change-the value of 3 changes accordinglyHow many days are there this month:Select DATEPART (Dd,dateadd (dd,-1,dateadd (MM,1,cast ((CAST (year (GETDATE ())As varchar) +‘-' +cast (Month (getdate ())As varchar) +‘-01‘ )As(datetime))), two time periods of difference:Select DateDiff (Day, ' 2012/8/1 ' 2012/8/20 "), Span style= "color: #800080;" >111) as Riqi // output 2012/ 8/21 ±n minutes on the specified date: select DateAdd (Mi,-15,getdate ()) " Span style= "color: #008000;" >// Query the date 15 minutes before the current time?
SQL Statistics Common SQL