ago • edited ago by
99 views
1 1 vote

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 = 'green'
AND NOT EXISTS (
    SELECT *
    FROM Product q
    WHERE q.brand = p.brand
    AND q.price > 100
);

Which TRC expression is equivalent?

  1. $\{t\mid \exists p\in \mathrm{Product}$
    $(p.\mathrm{color}=\mathrm{'green'}\land p.\mathrm{name}=t.\mathrm{name}$
    $\land \exists q\in \mathrm{Product}(q.\mathrm{brand}=p.\mathrm{brand}\land q.\mathrm{price}>100))\}$
     
  2. $\{t\mid \exists p\in \mathrm{Product}$
    $(p.\mathrm{color}=\mathrm{'green'}\land p.\mathrm{name}=t.\mathrm{name}$
    $\land \neg\exists q\in \mathrm{Product}(q.\mathrm{price}>100))\}$
     
  3. $\{t\mid \exists p\in \mathrm{Product}$
    $(p.\mathrm{color}=\mathrm{'green'}\land p.\mathrm{name}=t.\mathrm{name}$
    $\land \neg\exists q\in \mathrm{Product}(q.\mathrm{brand}=p.\mathrm{brand}\land q.\mathrm{price}>100))\}$
     
  4. $\{p\mid p\in \mathrm{Product}\land p.\mathrm{color}=\mathrm{'green'}\}$

1 Answer

0 0 votes

The outer SQL query requires a green product:

$p.\mathrm{color}=\mathrm{'green'}$.

It outputs only the product name:

$p.\mathrm{name}=t.\mathrm{name}$.

The $\text{NOT EXISTS}$ clause says there must not exist another product $q$ such that:

$q.\mathrm{brand}=p.\mathrm{brand}$

and

$q.\mathrm{price}>100$.

Therefore the correct condition is

$\neg\exists q\in \mathrm{Product}(q.\mathrm{brand}=p.\mathrm{brand}\land q.\mathrm{price}>100)$.

Putting everything together gives C.

A reverses the $\text{NOT EXISTS}$ meaning.

B rejects the product if any expensive product exists anywhere, rather than an expensive product of the same brand.

D simply returns every green product tuple.

Hence,

Answer : C

ago
Answer:
Position:
Show:

Related questions

1 1 vote
1 1 answer
145
145 views
GO Classes asked 5 days ago
145 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
57
57 views
GO Classes asked 5 days ago
57 views
Consider$\mathrm{Store}(\mathrm{sid},\mathrm{store\_name},\mathrm{parent\_company})$$\mathrm{Branch}(\mathrm{sid},\mathrm{city},\mathrm{open24})$$\mathrm{Has\_Fruit}(\mat...
0 0 votes
1 1 answer
62
62 views
GO Classes asked 5 days ago
62 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
60
60 views
GO Classes asked 5 days ago
60 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...