Home > database >  SQL have such operations, such as a field in a table, found to field a=1 data apart is the largest l
SQL have such operations, such as a field in a table, found to field a=1 data apart is the largest l

Time:10-07

My watch is such a ` ` ` ` a num field is continued, continuous line 1 of renewal, a code number is belong to, and there's a CREATE_DATE creation time, I want to check is ` ` ` in this week, for example, two of the same code to record the largest number apart (num field subtraction)

CodePudding user response:

Between two successive code, such as the num=10 code=3, num=20 code=3, num=50 code=3, found out is value is 30 (50-20=30)

CodePudding user response:

Select code, Max (num) from (
Select code, num - (select num from TB b where a.c ode=biggest ode and b.n um & lt; A.n um order by biggest reate_date desc, b.n um desc limit 1) as num
The from TB a
) data group by code

CodePudding user response:

M0_37175372
Junction post rate: 0%
The
reference

When you the solutions of the problems please post.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html

8, how to give points and knot stick?
http://bbs.csdn.net/help#post_dispose
  • Related