In the afternoon, I saw that a statistical report was generated for the project, in which the statistical time difference between two adjacent records recorded in the XX table is
The data in the table is as follows:
It is required that the creation time difference between two adjacent records, such as the 1st and 2nd record, be calculated.
That is,
zhouhui 5 seconds
24 seconds
##select
t.username,(max( t.CREATIONDATE)-
- ( t.CREATIONDATE))*24*60*60,
- count
(t.username)/2 ##from ofloginlog t
- ##--where USERNAME = 'zhouhui'
- group
by t.username
- Statistics of user online time are calculated through grouping (that is, the difference between the two records before and after )
Rendering: #Explanation that the last field is used to count the number of user logins.
The default value for oracle to subtract two times is the number of days
The default value for oracle to subtract two times is the number of days*24, which is the number of hours difference
The default value for subtraction is days*24*60, which is the number of minutes difference.
The default value for oracle subtraction between two times is number of days*24*60*60, which is the number of seconds difference.
select
username,sum
(b),count (username) / 2
from (select id, username, (CREATIONDATE - lgtime) * 24 * 60 * 60 as b
-
(type) over(partition by username order by
CREATIONDATE) lgtype, -
lag(CREATIONDATE) over(partition by username order by
CREATIONDATE) lgtime from ofloginlog t))
- ##-- where USERNAME = 'zhouhui')
- group
by username
## The effect is the same and I won’t post it here Reviewed the basic SQL again haha 20100520 Some changes in requirements require that the number of statistics is not the sum and mean of TYPE 1 and 0 records, but only the value of TYPE=0, This SQL grouping cannot be like this. I thought about it and improved the SQLSql code
g.username, g.
time, h.
count
from ( select t.username,
## floor((- max
(t.CREATIONDATE) - min(t.CREATIONDATE)) * 24 * 60 * 60) as time
# from ofloginlog t, ofuser b ## ## and t.username = b.username
-
(select t.username, count(t.username) as
count -
##where g.username = h.username
- ##order
by count desc
Query results The analysis time difference is the difference between the two sets, and the number of statistics later is only the number of records with a separate restriction of TYPE=0. The number of statistical data is inconsistent, so it is difficult to implement it in one group. The idea is to implement USERNAME and TIME first. The records count USERNAME and the number of records that satisfy TYPE=0 and merge the two results through the inline relationship of SELECT XX FROM A B 2 temporary tables to achieve the merged result set
This article explains SQL adjacent 2 Compare the time difference of records. For more related content, please pay attention to the PHP Chinese website. Related recommendations: .net2.0 connection Mysql5 database configuration
Detailed explanation of the difference between cookie and session
The above is the detailed content of SQL comparison of time difference between two adjacent records. For more information, please follow other related articles on the PHP Chinese website!

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

ToaddauserinMySQL,usetheCREATEUSERstatement.1)UseCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';tocreateauser.2)Enforcestrongpasswordpolicieswithvalidate_passwordpluginsettings.3)GrantspecificprivilegesusingGRANTstatement.4)Forremoteaccess,use

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor
