How to formulate "at most" in domain relational calculus

55 views Asked by At

How do I formulate "at most" in domain relational calculus?

Example queries:

Dish: dish_id, name
Have: dish_id, ing_id
Ingredient: ing_id, name
  • What are the names of ingredients included in at most two dishes?

  • What are the names of ingredients included in at most one dish?

1

There are 1 answers

0
philipxy On

There exist at least N ids when/iff there exist N ids.

-- there exists (at least) 1 id where p
exists x | p

-- there exist (at least) 2 ids where p
exists x,y | x<>y AND p

-- there exist (at least) 3 ids where p
exists x,y,z | x<>y AND x<>z AND y<>z AND p

There exist at most N ids when/iff NOT there exist N+1 ids.

-- there exist at most 2 things where p
-- NOT there exist (at least) 3 ids where p
NOT (exists x,y,z | x<>y AND x<>z AND y<>z AND p)

There exist exactly N ids when/iff there exist (at least) N ids and there exist at most N ids. Which is when/iff there exist (at least) N ids and NOT there exists one more id.

PS Be sure to know whether you want at least 1.

PS Difference between Relational Algebra and Relational Calculus