79 views
1 1 vote

Consider

$\mathrm{Store}(\mathrm{sid},\mathrm{store\_name},\mathrm{parent\_company})$

$\mathrm{Branch}(\mathrm{sid},\mathrm{city},\mathrm{open24})$

$\mathrm{Has\_Fruit}(\mathrm{sid},\mathrm{city},\mathrm{fid},\mathrm{quantity},\mathrm{price})$

$\mathrm{Fruit}(\mathrm{fruit\_id},\mathrm{name},\mathrm{calories})$.

Which TRC expression correctly returns the store names of stores that:

  • have a branch in $\mathrm{Berkeley}$,
     
  • are open at $2$ $\mathrm{AM}$,
     
  • have at least $5$ $\mathrm{pineapples}$,
     
  • charge less than $\$3$ per $\mathrm{pineapple}$, and
     
  • belong to parent company $\mathrm{WFM}$?
     
  1. $\{x\mid \exists s\in \mathrm{Store};\exists b\in \mathrm{Branch};\exists h\in \mathrm{Has\_Fruit};\exists f\in \mathrm{Fruit}$
    $(s.\mathrm{sid}=b.\mathrm{sid}$
    $\land s.\mathrm{sid}=h.\mathrm{sid}$
    $\land b.\mathrm{city}=h.\mathrm{city}$
    $\land h.\mathrm{fid}=f.\mathrm{fruit\_id}$
    $\land b.\mathrm{city}=\mathrm{'Berkeley'}$
    $\land b.\mathrm{open24}$
    $\land f.\mathrm{name}=\mathrm{'pineapple'}$
    $\land h.\mathrm{quantity}\geq 5$
    $\land h.\mathrm{price}<3$
    $\land s.\mathrm{parent\_company}=\mathrm{'WFM'}$
    $\land x.\mathrm{store\_name}=s.\mathrm{store\_name})\}$
     
  2. Same as A, but without $h.\mathrm{fid}=f.\mathrm{fruit\_id}$.
     
  3. Same as A, but with $h.\mathrm{quantity}<5$.
     
  4. Same as A, but without $s.\mathrm{sid}=b.\mathrm{sid}$ and $s.\mathrm{sid}=h.\mathrm{sid}$.

1 Answer

0 0 votes

Every condition in the English query must appear in the predicate.

The relation connections are essential:

$s.\mathrm{sid}=b.\mathrm{sid}$

connects a store to its branch.

$s.\mathrm{sid}=h.\mathrm{sid}$

and

$b.\mathrm{city}=h.\mathrm{city}$

connect the correct branch to its fruit inventory.

$h.\mathrm{fid}=f.\mathrm{fruit\_id}$

identifies which fruit the inventory record represents.

Then apply the required restrictions:

$b.\mathrm{city}=\mathrm{'Berkeley'}$

$b.\mathrm{open24}$

$f.\mathrm{name}=\mathrm{'pineapple'}$

$h.\mathrm{quantity}\geq 5$

$h.\mathrm{price}<3$

$s.\mathrm{parent\_company}=\mathrm{'WFM'}$.

Finally,

$x.\mathrm{store\_name}=s.\mathrm{store\_name}$

constructs the desired output.

Therefore A is correct.

Answer:
Position:
Show:

Related questions

1 1 vote
1 1 answer
164
164 views
GO Classes asked Sep 26
164 views
Consider$\mathrm{STUDENT}(\mathrm{name},\mathrm{regno},\mathrm{gpa},\mathrm{level},\mathrm{dept})$$\mathrm{COURSE}(\mathrm{cno},\mathrm{cname},\mathrm{dept})$$\mathrm{TAK...
1 1 vote
1 1 answer
119
119 views
GO Classes asked Sep 26
119 views
Consider$\mathrm{Product}(\mathrm{pid},\mathrm{name},\mathrm{brand},\mathrm{price},\mathrm{color})$.The SQL query is:SELECT DISTINCT name FROM Product p WHERE color = 'gr...
1 1 vote
1 1 answer
79
79 views
GO Classes asked Sep 26
79 views
Consider$\mathrm{Breeders}(\mathrm{brdr\_id},\mathrm{brdr\_name},\mathrm{age})$$\mathrm{Breeds}(\mathrm{br\_id},\mathrm{br\_name},\mathrm{friendliness})$$\mathrm{Pedigree...
1 1 vote
1 1 answer
73
73 views
GO Classes asked Sep 26
73 views
Consider $\mathrm{Pets}(\mathrm{pid},\mathrm{pname},\mathrm{weight})$.Which TRC expression returns only the weights of all pets whose name is $\mathrm{Tiny}$?$\{t\mid \ex...