Home > database >  Oracle SQL and how to realize the two periods o set
Oracle SQL and how to realize the two periods o set

Time:10-01

Table A has two fields, start_time and end_time, respectively, the article number is N, o, all the time and set the repeat period does not keep statistics.
Such as:
Start_time end_time
2017/2/1 12:06:17 2017/2/1 12:57:39
2017/2/1 12:30:01 2017/2/1 12:38:53
2017/2/1 19:34:28 2017/2/1 19:35:20
2017/2/1 19:35:20 2017/2/1 20:37:56
2017/2/1 20:37:57 2017/2/1 20:38:58
The results are as follows:
Start_time end_time
2017/2/1 12:06:17 2017/2/1 12:57:39
2017/2/1 19:34:28 2017/2/1 20:37:56
2017/2/1 20:37:57 2017/2/1 20:38:58

CodePudding user response:

You can use the intersects

CodePudding user response:

CodePudding user response:

 
The SELECT T.S TART_TIME
And NVL (MAX (C.E ND_TIME), T.E ND_TIME)
The FROM (SELECT DISTINCT A.S TART_TIME, A.E ND_TIME FROM TEST A
WHERE NOT the EXISTS (SELECT 1 FROM the TEST B WHERE B.S TART_TIME & lt; A.S TART_TIME AND B.E ND_TIME & gt; T=A.S TART_TIME)), the TEST C
WHERE T.E ND_TIME & gt; C.s. TART_TIME=(+)
AND T.E ND_TIME & lt; C.E ND_TIME (+)
GROUP BY T.S TART_TIME, T.E ND_TIME
The ORDER BY 1
  • Related