relational-algebra

Null in Relational Algebra

邮差的信 提交于 2020-03-19 06:10:03
问题 I want to query the id of all apartments that were never rented I tried something like this: (π a_id (apartments)) - (π a_id σ from_date Exists ∧ end_date Exists (rental) ⨝ rental.a_id on apartment.a_id (apartment)) But I think I cannot use Exist in relational algebra or null or anything. How could I do it? Thanks I attach the schema here 回答1: For the most straightforward relational algebra, where a relation has an attribute set as heading & tuple set as body: Presumably apartment ids in

How to fetch distinct values with arel/relational algebra and has_many :through

安稳与你 提交于 2020-02-02 07:22:52
问题 When I try to display all movies that a person is in, and they have more than 1 role (director,writer,actor) in a movie, I get multiple lines for that movie. If I add .select('DISTINCT id') or movies.* to try and eliminate the dups I get the following error: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT id FROM movies INNER JOIN movie_people ON movies .id = movie_peop' at line 1:

How to fetch distinct values with arel/relational algebra and has_many :through

孤街醉人 提交于 2020-02-02 07:22:15
问题 When I try to display all movies that a person is in, and they have more than 1 role (director,writer,actor) in a movie, I get multiple lines for that movie. If I add .select('DISTINCT id') or movies.* to try and eliminate the dups I get the following error: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT id FROM movies INNER JOIN movie_people ON movies .id = movie_peop' at line 1:

Database Relational Algebra: How to find actors who have played in ALL movies produced by “Universal Studios”?

梦想与她 提交于 2020-01-22 03:49:05
问题 Given the following relational schemas, where the primary keys are in bold: movie( movieName , whenMade); actor( actorName , age); studio( studioName , location, movieName); actsIn( actorName , movieName ); How do you find the list of actors who have played in EVERY movie produced by "Universal Studios"? My attempt: π actorName ∩ (σ studioName=“Universal Studios” studio) |><| actsIn, where |><| is the natural join Are you supposed to use cartesian product and/or division? :\ 回答1: Here are the

Functional Dependencies examples

情到浓时终转凉″ 提交于 2020-01-05 05:35:09
问题 So to sum it all up, i am having major difficulties understanding functional dependencies just by looking at abstract examples and would really appreciate some help of understanding with possible real life situations. I want to see if these functional dependencies is any BCNF violation. I have read alot of explainations but im still struggling with understanding fully and i cannot understand the full picture only by looking at characters such as the below. I feel like i need some real data to

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

不问归期 提交于 2020-01-03 03:19:30
问题 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 relational algebra representation of only returning all unique (x, y) tuples? For example, I would like the following (x,y) tuples returned in the above table: (1,3), (2,2) (2,3), and (3,3). Thanks 回答1: Rename R to S S := ρ S/R (R) 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

How to find all pizzerias that serve every pizza eaten by people over 30?

限于喜欢 提交于 2019-12-31 14:36:35
问题 I'm following the Stanford Database course and there's a question where we have Find all pizzerias that serve every pizza eaten by people over 30 using Relational Algebra only. The problem consist of a small database with four relations: Person(name, age, gender) // name is a key Frequents(name, pizzeria) // [name,pizzeria] is a key Eats(name, pizza) // [name,pizza] is a key Serves(pizzeria, pizza, price) // [pizzeria,pizza] is a key I know how to find which pizza's people over 30 eat and

Lossless Join and Decomposition From Functional Dependencies

倾然丶 夕夏残阳落幕 提交于 2019-12-31 10:49:27
问题 Suppose the relation R( K, L, M, N, P) , and the functional dependencies that hold on R are: - L -> P - MP -> K - KM -> P - LM -> N Suppose we decompose it into 3 relations as follows: - R1(K, L, M) - R2(L, M, N) - R3(K, M, P) How can we tell whether this decomposition is lossless? I used this example R1 ∩ R2 = {L, M}, R2 ∩ R3 = {M}, R1 ∩ R3 = {K,M} we use functional dependencies, and this is not lossless in my opinion, but a little bit confused. 回答1: It helps if we demystify the concept of

Cartesian products of tables that contains same columns

随声附和 提交于 2019-12-31 03:59:06
问题 I am really confused about this. I searched a lot of tutorials but i couldnot find a clear answer. A B B D 1 X x 5 2 x y 6 x 4 I want to cross this two tables.A , B, B,d are attributes. A B B D 1 X x 5 2 x x 5 1 X y 6 2 x y 6 1 X x 4 2 x x 4 This should be answer normally according to rule of cartesian. Cross all rows. But i am confused about same column B. Same column will seem twice? 回答1: Some relational query language/algebra relations have ordered column names . There is a way to

Expressing “is null” in Relational algebra

北战南征 提交于 2019-12-29 09:25:10
问题 In SQL, if I want to know whether an expression is NULL, I can use is null . But I don't understand how I can express is null in relational algebra. Can I use δ Field_Name=NULL(Table_Name) ? 回答1: There is no NULL in relational algebra. In SQL the operators treat the value NULL specially, syntactically and semantically, differently than other values, usually by returning NULL when comparing two values when one of them is NULL. So "=" in a WHERE is not equality, it is an operator like equality