Home > database > SQL statement of how to implement the following functions
SQL statement of how to implement the following functions
Time:10-13
If you have the following tableA:
Id name the start_date end_date 1 Amy 8/1/2019 9/23/2019 2 Bob 8/2/2019 9/24/2019 3 Cathy 8/3/2019 9/25/2019 4 Amy 10/4/2019 10/26/2019 5 Amy 8/5/2019 9/29/2019
How to find out the name duplication, overlap of data and time?
Should be found in article 1 and article 5 of the data (because of article 4 of the data is not overlap with other name is Amy's time) : Id name the start_date end_date 1 Amy 8/1/2019 9/23/2019 5 Amy 8/5/2019 9/29/2019
CodePudding user response:
Since the connection line
WITH TMP AS (SELECT 1 ID, 'Amy' AS the NAME, TO_DATE (' 8/1/2019 ', 'the mm/dd/yyyy) AS the START_DATE, TO_DATE (' 9/23/2019 ', 'the mm/dd/yyyy) AS END_DATE The FROM DUAL UNION ALL SELECT 2, 'Bob' AS the NAME, TO_DATE (' 8/2/2019 ', 'the mm/dd/yyyy), TO_DATE (' 9/24/2019 ', 'the mm/dd/yyyy) The FROM DUAL UNION ALL SELECT 3, 'Cathy' AS the NAME, TO_DATE (' 8/3/2019 ', 'the mm/dd/yyyy), TO_DATE (' 9/25/2019 ', 'the mm/dd/yyyy) The FROM DUAL UNION ALL SELECT 4, 'Amy' AS the NAME, TO_DATE (' 10/4/2019 ', 'the mm/dd/yyyy), TO_DATE (' 10/26/2019 ', 'the mm/dd/yyyy) The FROM DUAL UNION ALL SELECT 5, 'Amy' AS the NAME, TO_DATE (' 8/5/2019 ', 'the mm/dd/yyyy), TO_DATE (' 9/29/2019 ', 'the mm/dd/yyyy) The FROM DUAL) SELECT A. * The FROM TMP A INNER JOIN TMP B ON B.I D & lt;> Anderson, D AND B.N AME=A.N AME AND B.S TART_DATE & lt;=A.E ND_DATE AND B.E ND_DATE & gt;=A.S TART_DATE The ORDER BY Anderson D
CodePudding user response:
Thank you very much! If the actual TableA particularly large amount of data, not list?
CodePudding user response:
Analysis function, use the two as a dimension, and then the count
CodePudding user response:
Written as data will be divergent, many-to-many associations affected the accuracy of the data,