How to find all tuples in a table if and only if the tuple appears once?

前端 未结 1 1085
野性不改
野性不改 2021-01-16 19:15

I have a table:

x | y | z
------------
1 | 1 | *
1 | 1 | *
1 | 3 | *
2 | 2 | *
2 | 3 | *
3 | 4 | *
3 | 4 | * 
3 | 3 | *

What is the relatio

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 19:28

    1. Rename R to S

      S := ρS/R(R)

    2. Join R and S on x,y

      D := R ⋈S.x = R.x ∧ S.y = R.y S

      This squares the number of tuples with a particular value for (x,y). Particularly, if a value for (x,y) appears only once in R, it appears only once in D.

    3. Join R and S on x,y,z

      E := R ⋈S.x = R.x ∧ S.y = R.y ∧ S.z = R.z S

      This basically adds some columns to R. It does not add or remove tuples.

    4. Subtract E from D and project to the attributes of R

      F := πx,y,z(D\E)

      This removes the tuples from D, that where created by joining a tuple from R to the corresponding tuple in S. The remaining tuples are the ones that where created by joining a tuple in R to a different tuple in S. Particularly, if a value for (x,y) appears only once in R, no tuple in F exists with that value.

    5. Remove the tuples in F from R

      R\F

    0 讨论(0)
提交回复
热议问题