Home > database >  How using mySQL this time function for the first time
How using mySQL this time function for the first time

Time:09-29










 


SELECT
The UserName
, GMTDate
, the Sum (FlowCount) as FlowCount
[Type]
The FROM [LOGSERVER] [dbo]. [CDNHTTP]
Where DATEDIFF (month, [GMTDate], GETDATE ())=2//change this data can be a month


Group by [UserName], [GMTDate], [Type]
The order by [GMTDate]



This is MS SQL function, realized to mySQL to do now?

Has examined the mySQL with DATEDIFF but return it without parameters, DATE_SUB seems to also not line, do not know how

CodePudding user response:

Is about such a MSSQL table

 

The CREATE TABLE [dbo] [CDNHTTP] (
[ID]/int IDENTITY (1, 1) NOT NULL,
[UserName] [varchar] (50) NULL,
[GMTDate] [datetime2] (7) NULL,
[FlowCount] [float] NULL,
[Type] [varchar] (255), NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
) WITH (PAD_INDEX=OFF, STATISTICS_NORECOMPUTE=OFF, IGNORE_DUP_KEY=OFF, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON (PRIMARY)
) ON the (PRIMARY)

GO

The SET ANSI_PADDING OFF
GO


Records have the time, site, traffic is used, use agreement,

Flow in each site usage statistics, showed that on the day of the deadline for the month

Such as: need statistics each site traffic situation every day last month, MS SQL below

 

SELECT
The UserName
, GMTDate
, the Sum (FlowCount) as FlowCount
[Type]
The FROM [LOGSERVER] [dbo]. [CDNHTTP]
Where DATEDIFF (month, [GMTDate], GETDATE ())=1

Group by [UserName], [GMTDate], [Type]
The order by [GMTDate]




This month is just change parameter where DATEDIFF (month, [GMTDate], GETDATE ())=[color=# FF0000] 0
[/color]
By analogy, so how should the mySQL query the,

Thank you for the first time to use mySQL

CodePudding user response:



MS SQL is the


MySQL that seems to be no

CodePudding user response:

MYSQL datediff such use
 DATEDIFF (CURDATE (), [GMTDate])=2 

CodePudding user response:

The SELECT DATEDIFF (' 2008-12-30 ', '2008-12-29') AS DiffDate
Mysql returned with this days,

CodePudding user response:

The
reference 3 floor roy_88 response:
MYSQL datediff such use
 DATEDIFF (CURDATE (), [GMTDate])=2 


This can only look up one day DATEDIFF in msSQL is punctuated with three parameters

DATEDIFF (datepart, startdate, enddate)

The first is by what time interval check

Corresponding to the mySQL

Hh TimeDiff
DATEDIFF is day

Now to parameter is a month? What should we do with mySQL? Corresponding which function? The need to calculate the month days then use DATEDIFF?

CodePudding user response:





CodePudding user response:

The
reference 4 floor liuzhijian2008x reply:
SELECT DATEDIFF (' 2008-12-30 ', '2008-12-29') AS DiffDate
Mysql with this return to the days,


Was thinking whether to do so! The feeling didn't also other methods

CodePudding user response:

reference 5 floor e8love reply:
parameter is a month now? What should we do with mySQL? Corresponding which function? The need to calculate the month days then use DATEDIFF?


Take in a date format function date_format
Date_format (GMTDate, '% Y - % m)=date_format (DATE_SUB (curdate (), 2 MONTH INTERVAL),' % % Y - m)

CodePudding user response:



With out

CodePudding user response:

references 9 f e8love response:


Tossing out


Which data_SUB change parameter values, query this month last month N month ago

CodePudding user response:

refer to the eighth floor roy_88 response:
Quote: refer to the fifth floor e8love reply:

Now to parameter is a month? What should we do with mySQL? Corresponding which function? The need to calculate the month days then use DATEDIFF?


Take in a date format function date_format
Date_format (GMTDate, '% Y - % m)=date_format (DATE_SUB (curdate (), 2 MONTH INTERVAL),' % Y - % m ')





Thank you very much this is really what I want, that can only take out this month and months above sum

Thank you for the
  • Related