0
私はAmazon RedShift PostgreSQL
データベースを使用しています。 重複レコードを持っている。ここSQL - 同じテーブルの他のレコードと一致するレコードを取得する
| id | patientname | providername | eventid | eventstart | eventend | isactive | segmentcode | Description |
|----|---------------|--------------|---------|---------------------|---------------------|----------|-------------|------------------------|
| 1 | Susie Jones | John Melton | 340000 | 2017-08-08 10:00:00 | 2017-08-08 10:00:00 | true | 845685 | Reminder Call |
| 2 | Susie Jones | John Melton | 340000 | 2017-08-08 10:00:00 | 2017-08-08 10:30:00 | true | 365478 | Steam Therapy Session |
| 3 | Roschel Ross | Kate Winny | 350000 | 2017-08-09 11:00:00 | 2017-08-09 11:00:00 | true | 845685 | Reminder Call |
| 4 | Roschel Ross | Kate Winny | 350000 | 2017-08-09 11:00:00 | 2017-08-09 13:30:00 | true | 367545 | Physio Therapy Session |
| 5 | Lilly Hodge | Jessica | 360000 | 2017-08-09 11:00:00 | 2017-08-09 11:00:00 | true | 754544 | Doctor appointment |
| 6 | Jack Richards | Mike Chong | 37000 | 2017-08-10 17:00:00 | 2017-08-10 17:30:00 | true | 889754 | Sample Appointment |
| 7 | Sammy Jones | Winsten | 38000 | 2017-08-10 17:00:00 | 2017-08-10 18:30:00 | true | 845685 | Physio Therapy Session |
| 8 | Sammy Jones | Winsten | 38000 | 2017-08-10 17:00:00 | 2017-08-10 17:00:00 | true | 454542 | Reminder Call |
は、あなたには、いくつかのレコードがsegmentcode 845685である見ることができ、すべてのこれらのレコード:予定のこのような記録を保存する私のデータベース内のテーブルがあり
異なるセグメントコードで同じイベントIDと同じです。
は、私が欲しいのはその重複するレコードとともにセグメントコード845685とレコードを取得SQLクエリを使用して、あります。結果テーブルは次のようになります。
| id | patientname | providername | eventid | eventstart | eventend | isactive | segmentcode | Description |
|----|---------------|--------------|---------|---------------------|---------------------|----------|-------------|------------------------|
| 1 | Susie Jones | John Melton | 340000 | 2017-08-08 10:00:00 | 2017-08-08 10:00:00 | true | 845685 | Reminder Call |
| 2 | Susie Jones | John Melton | 340000 | 2017-08-08 10:00:00 | 2017-08-08 10:30:00 | true | 365478 | Steam Therapy Session |
| 3 | Roschel Ross | Kate Winny | 350000 | 2017-08-09 11:00:00 | 2017-08-09 11:00:00 | true | 845685 | Reminder Call |
| 4 | Roschel Ross | Kate Winny | 350000 | 2017-08-09 11:00:00 | 2017-08-09 13:30:00 | true | 367545 | Physio Therapy Session |
| 7 | Sammy Jones | Winsten | 38000 | 2017-08-10 17:00:00 | 2017-08-10 18:30:00 | true | 845685 | Physio Therapy Session |
| 8 | Sammy Jones | Winsten | 38000 | 2017-08-10 17:00:00 | 2017-08-10 17:00:00 | true | 454542 | Reminder Call |
どうすればいいですか?
INでサブクエリを実行するとパフォーマンスが向上しますか?何千もの記録があります。 – Dev