มีสองตารางข้อมูลเรียบร้อยแล้ว(table1, table2)กับเดียวกันคอลัมน์รายชื่อ(รุ่น, พ่อแม่),ที่ต้องการแสดงผลจะเป็นจากการรวมเข้าด้วยกันของทุกคอลัมน์ของทั้งสองตารางข้อมูลเรียบร้อยแล้ว. มันรวนแถวของ table2 ควรจะมาร่วมกับ table1 ดังนั้นว่าคนวนแถวของ table2 เป็นตรงกับพวกนั้นของ table1 บ คนรุ่น วนคอลัมน์ พ่อแม่เบอร์ควรจะสั่งการส่งจดหมายสำหรับรายการใน table1 เช่นเดียวใน table2. จำนวนแถวของกับการค้นหาผลลัพธ์ควรจะเท่ากับของพวกนั้นของ table1.
ให้คนตามตารางข้อมูลเรียบร้อยแล้ว
table1:
| generation | parent |
|:----------:|:------:|
| 0 | 1 |
| 0 | 2 |
| 0 | 3 |
| 1 | 3 |
| 1 | 2 |
| 1 | 1 |
| 2 | 2 |
| 2 | 1 |
| 2 | 3 |
table2:
| generation | parent |
|:----------:|:------:|
| 1 | 3 |
| 1 | 1 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
ที่ติดตามค้นข้อมูลกำนคิดว่าสำหรับสร้างและ populating สองตัวอย่างตารางข้อมูลเรียบร้อยแล้วที่แสดงด้านบน:
create table table1(generation integer, parent integer);
insert into table1 (generation, parent) values(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(2,2),(2,1),(2,3);
create table table2(generation integer, parent integer);
insert into table2 (generation, parent) values(1,3),(1,1),(1,3),(2,1),(2,2),(2,3);
ในจินตนาการสืบค้นควรจะนำไปสู่ต่อไปนี้ ปรารถนาผล:
| table1_generation | table1_parent | table2_generation | table2_parent |
|:-----------------:|:-------------:|:-----------------:|:-------------:|
| 0 | 1 | | |
| 0 | 2 | | |
| 0 | 3 | | |
| 1 | 1 | 1 | 1 |
| 1 | 2 | 1 | 3 |
| 1 | 3 | 1 | 3 |
| 2 | 1 | 2 | 1 |
| 2 | 2 | 2 | 2 |
| 2 | 3 | 2 | 3 |
ปัจจุบันกับการค้นหาดูเหมือนติดตาม:
with
p as (
select
generation,
parent
from
table1
order by
generation,
parent
), o as(
select
generation,
parent
from
table2
order by
generation,
parent
)
select
p.generation as table1_generation,
p.parent as table1_parent,
o.generation as table2_generation,
o.parent as table2_parent
from
p
left join o on
o.generation=p.generation;
ฟังก์ชั่นการรับรู้เสื่อมถอยการต่อผลลัพธ์:
| table1_generation | table1_parent | table2_generation | table2_parent |
|:-----------------:|:-------------:|:-----------------:|:-------------:|
| 0 | 1 | | |
| 0 | 2 | | |
| 0 | 3 | | |
| 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 3 |
| 1 | 1 | 1 | 3 |
| 1 | 2 | 1 | 1 |
| 1 | 2 | 1 | 3 |
| 1 | 2 | 1 | 3 |
| 1 | 3 | 1 | 1 |
| 1 | 3 | 1 | 3 |
| 1 | 3 | 1 | 3 |
| 2 | 1 | 2 | 1 |
| 2 | 1 | 2 | 2 |
| 2 | 1 | 2 | 3 |
| 2 | 2 | 2 | 1 |
| 2 | 2 | 2 | 2 |
| 2 | 2 | 2 | 3 |
| 2 | 3 | 2 | 1 |
| 2 | 3 | 2 | 2 |
| 2 | 3 | 2 | 3 |
ส่วนเชื่อมโยงนี้จะ นำไปสู่การสรุปนั่นมีร่วมกับคำสั่งอาจจะไม่ใช่มันคืออะไรจำเป็นต้องอยู่ที่นี่แต่นสหภาพเดียวที่ทำต่อไปยังท้ายแถว...ดังนั้นสำหรับฉันมันเป็นแน่นอนอยู่ยังไม่ค่อยแน่ใจได้ยังไงที่ต้องการผลลัพธ์เป็นประสบความสำเร็จโอ.โอ
มีความช่วยเหลือเป็นเกียรติอย่างยิ่ง ขอบคุณล่วงหน้า!