Home > database > MYSQL how to check the time interval between multiple records?
MYSQL how to check the time interval between multiple records?
Time:10-10
A table for the target phone number B table for the data table, phone number, transaction amount, transaction completion time, Think through the following statements and calculate the query each time each time lag between the time, SELECT A. ` mobile number `, B. ` deal ` AS time The FROM ` mobile number ` AS A, ` cashier ` AS B Where a. ` mobile number `=b. ` mobile number ` GROUP BY a. ` mobile number `, b. ` deal completion time `
Difficulties: I am a little white, don't know how to calculate multiple transaction completion time lag, A mobile phone number have shopping time for many times, some also only once, so I don't know what to do, https://bbs.csdn.net/topics/320082158 this post I also saw, don't know how to write, and imitation is not successful,
The ideal result is: Mobile phone number transaction completion time lag 555, 20200606, 555 20200607 1 555, 20200610, 3 666, 20200611,
So, probably, you help to look at the great god, I asked the bosses have broadly fall,
CodePudding user response:
This is the result of my above statement data query,,
CodePudding user response:
With cs as ( Select a phone number, date, row_number () over (order by phone number) as id from the table ) Mobile phone number, select a. a. date, case when b.i d is null then 0 else a. end date - b. date ce The from cs on Anderson, a left join cs b d=b.i d + 1 and a. phone number=b. phone number