So they do not consider entries customer who don't visit any of the shops or he must visit at least one shop for being a part of the customer relation.

Dark Mode

2,695 views

36 votes

In a relational database there are three relations:

- $Customers = C \textsf{(CName)}$
- $Shops = S \textsf{(SName)}$
- $Buys = B \textsf{(CName, SName)}$

Then the Relational Algebra expression ( $\Pi $ is the projection operator).

$C-\Pi _\textsf{CName}((C \times S)-B)$

returns the names of

- Customers who buy from at least one shop.
- Customers who buy from at least two shops.
- Customers who buy from all shops.
- Customers who do not buy buy anything at all.
- None of the above.

The key point here is we don't have to take a tuple in the customer who don't visit any of the shop else Relation algebra expression will give different solution.

So they do not consider entries customer who don't visit any of the shops or he must visit at least one shop for being a part of the customer relation.

So they do not consider entries customer who don't visit any of the shops or he must visit at least one shop for being a part of the customer relation.

0

0

33 votes

Best answer

It is division in relational algebra

Division = ${\pi_{AB}} (R) /{\pi_ {B}} (S)$ Results in 'A' values for which here should be 'B' in R for every 'B' of S.

${\pi _{AB}}(R)/{\pi_{B}} (S) = {\Pi _{A}}(R) -{\pi _ {A}}({\pi _ {A}}(R)\times S-R)$ Retrieve all A's who are related to every B

$C−{\Pi_{CName}}((C\times S)−B)$

$C\times S$ gives the complete relation of each customer to every shop

$(C\times S)−B)$ :gives the relation of the customer which is not related to every shop.

${\Pi_{CName}}((C\times S)−B)$: gives the customer name who is not related to every shop.

$C−{\Pi_{CName}}((C\times S)−B)$: gives the customer who is related to every shop.

**Option C) Customers who buy from all shops.**

17 votes

lets solve by taking example

Customer

Customer name |

A |

B |

C |

Shop

name |

1 |

2 |

C*S will be possible combinations of customers and shop(cartesian product)

∏name (C*S-B ) will give names of customers who do not went to all shop in our example its B and C

now when we C-∏name (C*S-B ) we get A as output

so output will be name of employees who went to every shop

2 votes

According to me Best approach to solve such question is by taking example which includes all possible options.

In case one of option is given "none of above" in that case be also check whether final answer returns null , or multiple value.

This approach is time taking but gives correct result.

customers : A,B,C,D shops: P1,P2,P3

Buys

A | P1 |

B | P2 |

B | P2 |

C | P1 |

C | P2 |

C | P3 |

reason why only this table taken

first row :

Customers who buy from at least one shop. -> then A must be there, and D will not be there

second and third row

Customers who buy from at least two shops.-> then B will be there and A, D will not be there

4,5,6th

Customers who buy from all shops. -> then C will be there A, B, D will not be there.

No row for D:

Customers who do not buy buy anything at all. ->D will be there A, B, C will not be there

ΠCName((C×S)−B)

gives

A | P2 |

A | P3 |

B | P1 |

D | P1 |

D | P2 |

D | P3 |

I know projection will return just (A, B, D) , but for understanding purpose i have written like this

final answer

C