An example of a database self-join query

Source: Internet
Author: User

Call record ID that is greater than 10 seconds between two calls of the same number

Example: 6,7,8,9,10 records are consistent with

ID caller number called number call start time call end time talk length

1 98290000 0215466546656 2007-02-01 09:49:53.000 2007-02-01 09:50:16.000 23

2 98290000 021546654666 2007-02-01 09:50:29.000 2007-02-01 09:50:41.000 12

3 98290000 021546654666 2007-02-01 09:50:58.000 2007-02-01 09:51:12.000 14

4 68290900 0755133329866 2007-02-01 10:04:31.000 2007-02-01 10:07:13.000 162

5 78290000 0755255708638 2007-02-01 10:48:26.000 2007-02-01 10:49:23.000 57

6 78290000 0755821119109 2007-02-01 10:49:39.000 2007-02-01 10:52:55.000 196

7 78290000 035730928370 2007-02-01 11:30:45.000 2007-02-01 11:31:58.000 73

8 78290000 0871138889904 2007-02-01 11:33:47.000 2007-02-01 11:35:00.000 73

9 68290000 035730928379 2007-02-01 11:52:20.000 2007-02-01 11:54:56.000 156

10 68290000 0298521811199 2007-02-01 12:44:45.000 2007-02-01 12:45:04.000 19

Answer:

SELECT DISTINCT a.* from DBO.HC a left joins DBO.HC B on    A. Calling number =b. Caller number where a.id<>b.id and     (DATEDIFF (second,a . Call start time, B. Call end time) >10     and DATEDIFF (second,b. Call start time, a. Call end time) >10)

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.