Podcast
Questions and Answers
Which of the following queries will list all details from the staff
table, placing individuals with the last name 'Yandle' at the top of the result set?
Which of the following queries will list all details from the staff
table, placing individuals with the last name 'Yandle' at the top of the result set?
- `SELECT * FROM staff WHERE lastname = 'Yandle';`
- `SELECT * FROM staff ORDER BY lastname DESC;`
- `SELECT * FROM staff ORDER BY firstname ASC;`
- `SELECT * FROM staff ORDER BY lastname ASC;` (correct)
Consider a database schema with a course
table. Which SQL query accurately selects the name
of all courses that are either level 3 or 4, have more than 10 credits, and are not offered in semester 2?
Consider a database schema with a course
table. Which SQL query accurately selects the name
of all courses that are either level 3 or 4, have more than 10 credits, and are not offered in semester 2?
- `SELECT name FROM course WHERE semester = 2 AND credits > 10;`
- `SELECT name FROM course WHERE credits > 10;`
- `SELECT name FROM course WHERE level > 2 AND credits > 10;`
- `SELECT name FROM course WHERE level IN (3, 4) AND credits > 10 AND semester != 2;` (correct)
Given a staff
table, which SQL query effectively identifies staff members who have either a missing phone number or a missing office number in the database?
Given a staff
table, which SQL query effectively identifies staff members who have either a missing phone number or a missing office number in the database?
- `SELECT lastname FROM staff WHERE phone IS NULL AND office IS NULL;`
- `SELECT lastname FROM staff WHERE phone IS NULL OR office IS NULL;` (correct)
- `SELECT lastname FROM staff WHERE phone IS NOT NULL AND office IS NOT NULL;`
- `SELECT lastname FROM staff WHERE phone IS NOT NULL OR office IS NOT NULL;`
Assuming tables named allmarks17
and course
exist, which SQL query correctly retrieves the banner code (bc
) and name
of courses taken by students in the year 2017?
Assuming tables named allmarks17
and course
exist, which SQL query correctly retrieves the banner code (bc
) and name
of courses taken by students in the year 2017?
Using SQL, how would you list the name
of courses that were not taught in 2017 but had students who took exams for them in 2017, assuming data exists in tables named course
, allmarks17
, and lecturing
?
Using SQL, how would you list the name
of courses that were not taught in 2017 but had students who took exams for them in 2017, assuming data exists in tables named course
, allmarks17
, and lecturing
?
Considering a staff
table with phone
and office
columns, which SQL query identifies the last names of staff who have a phone number recorded but do not have an office number recorded, utilizing the EXCEPT
operator?
Considering a staff
table with phone
and office
columns, which SQL query identifies the last names of staff who have a phone number recorded but do not have an office number recorded, utilizing the EXCEPT
operator?
Given a lecturing
table, which SQL query lists course IDs (cid
) for courses that were newly introduced in the year 2015, meaning they were not taught in any year prior to 2015?
Given a lecturing
table, which SQL query lists course IDs (cid
) for courses that were newly introduced in the year 2015, meaning they were not taught in any year prior to 2015?
Assuming a lecturing
table exists, which SQL query correctly lists course IDs (cid
) along with the average enrolment (AVG(numbers)
) and the count of distinct staff members (COUNT(DISTINCT sid)
) for each course?
Assuming a lecturing
table exists, which SQL query correctly lists course IDs (cid
) along with the average enrolment (AVG(numbers)
) and the count of distinct staff members (COUNT(DISTINCT sid)
) for each course?
Given a lecturing
table, which SQL query identifies courses that were repeated in the same year, using the GROUP BY
clause?
Given a lecturing
table, which SQL query identifies courses that were repeated in the same year, using the GROUP BY
clause?
With a table named allmarks17
, which SQL query computes the total number of distinct students and courses in a single query?
With a table named allmarks17
, which SQL query computes the total number of distinct students and courses in a single query?
Assuming there is a table named allmarks
, which SQL query lists course banner codes (bc
) along with the average marks for both 2016 and 2017, but only for courses that have data for both years?
Assuming there is a table named allmarks
, which SQL query lists course banner codes (bc
) along with the average marks for both 2016 and 2017, but only for courses that have data for both years?
Given tables named staff
and lecturing
, which SQL query lists the last names of staff members who did not lecture?
Given tables named staff
and lecturing
, which SQL query lists the last names of staff members who did not lecture?
How can you generate a course statistics report ordered alphabetically by course name, given tables named course
and allmarks18
?
How can you generate a course statistics report ordered alphabetically by course name, given tables named course
and allmarks18
?
In a database with a staff
table, how would you identify staff members who share an office?
In a database with a staff
table, how would you identify staff members who share an office?
Given the relational algebra expression σ_{D=p}(π_{X,Y}(T1) ⋈ π_{X,D}(T2)), what is the number of tuples in the result?
Given the relational algebra expression σ_{D=p}(π_{X,Y}(T1) ⋈ π_{X,D}(T2)), what is the number of tuples in the result?
Which relational algebra expression is equivalent to the following SQL query: Find staff names with lastname 'Jung' from the years 2013 or 2014?
Which relational algebra expression is equivalent to the following SQL query: Find staff names with lastname 'Jung' from the years 2013 or 2014?
Assuming a database contains a lecturing
table, which SQL query lists the course IDs (cid
) of courses that had an increase in enrolment numbers from 2016 to 2017?
Assuming a database contains a lecturing
table, which SQL query lists the course IDs (cid
) of courses that had an increase in enrolment numbers from 2016 to 2017?
Given a table named allmarks18
, which SQL query calculates the 'hard-failure rate' for each course?
Given a table named allmarks18
, which SQL query calculates the 'hard-failure rate' for each course?
What information is returned by the following relational algebra expression: π_{lastname}(σ_{numbers > 100}(staff ⋈ lecturing))?
What information is returned by the following relational algebra expression: π_{lastname}(σ_{numbers > 100}(staff ⋈ lecturing))?
Which SQL query accurately represents the following relational algebra expression: π_{name}(σ_{numbers > 100}(lecturing ⋈ course)) - π_{name}(σ_{level=1}(course))?
Which SQL query accurately represents the following relational algebra expression: π_{name}(σ_{numbers > 100}(lecturing ⋈ course)) - π_{name}(σ_{level=1}(course))?
Given tables T1(A, B, C) and T2(B, C, D), how many tuples result from the natural inner join T1 ⋈ T2?
Given tables T1(A, B, C) and T2(B, C, D), how many tuples result from the natural inner join T1 ⋈ T2?
Given tables T1(A, B, C) and T2(B, C, D), how many tuples result from the natural full outer join T1 ⟗⟖ T2?
Given tables T1(A, B, C) and T2(B, C, D), how many tuples result from the natural full outer join T1 ⟗⟖ T2?
In a tourist information system, what is the most likely multiplicity relationship between City
and County
?
In a tourist information system, what is the most likely multiplicity relationship between City
and County
?
For a hotel database, which description best defines the relationship of a Room
to Accommodation
?
For a hotel database, which description best defines the relationship of a Room
to Accommodation
?
In a car rental system, what is the multiplicity relationship between Customer
and Vehicle Class
?
In a car rental system, what is the multiplicity relationship between Customer
and Vehicle Class
?
Which of the following schemas correctly represents the Attraction
table in a tourist information database?
Which of the following schemas correctly represents the Attraction
table in a tourist information database?
Which SQL CREATE TABLE
statement correctly corresponds to a Street
table, including a foreign key relationship to a City
table with cascade delete?
Which SQL CREATE TABLE
statement correctly corresponds to a Street
table, including a foreign key relationship to a City
table with cascade delete?
In a hotel context, what multiplicity best describes the relationship between Hotel
and Meeting Room
?
In a hotel context, what multiplicity best describes the relationship between Hotel
and Meeting Room
?
Within the context of the UN system, which multiplicity best describes the relationship between a Country
and an Alliance
?
Within the context of the UN system, which multiplicity best describes the relationship between a Country
and an Alliance
?
In a car rental system, how should the eligibility of employees to provide discounts to commercial customers be modeled?
In a car rental system, how should the eligibility of employees to provide discounts to commercial customers be modeled?
Which database schema best represents the Rental
table in a car rental system?
Which database schema best represents the Rental
table in a car rental system?
In a car rental system, how would you represent the relationship between commercial customers and their eligible employees?
In a car rental system, how would you represent the relationship between commercial customers and their eligible employees?
Flashcards
ORDER BY lastname ASC
ORDER BY lastname ASC
Sorts results alphabetically, so 'Yandle' appears early.
Course Selection Query
Course Selection Query
Filters by level (3 or 4), credits (>10), excluding semester 2.
IS NULL Operator
IS NULL Operator
Checks for staff with either missing phone OR office numbers.
Table JOIN
Table JOIN
Signup and view all the flashcards
IN and NOT IN
IN and NOT IN
Signup and view all the flashcards
EXCEPT Operator
EXCEPT Operator
Signup and view all the flashcards
Find New Courses
Find New Courses
Signup and view all the flashcards
AVG and COUNT(DISTINCT)
AVG and COUNT(DISTINCT)
Signup and view all the flashcards
GROUP BY for Duplicates
GROUP BY for Duplicates
Signup and view all the flashcards
COUNT(DISTINCT)
COUNT(DISTINCT)
Signup and view all the flashcards
CASE WHEN with AVG
CASE WHEN with AVG
Signup and view all the flashcards
Staff Who Didn't Lecture
Staff Who Didn't Lecture
Signup and view all the flashcards
Aggregate Course Stats
Aggregate Course Stats
Signup and view all the flashcards
Self-Join
Self-Join
Signup and view all the flashcards
Join with Filtering
Join with Filtering
Signup and view all the flashcards
City-County relationship
City-County relationship
Signup and view all the flashcards
Hotels and Room Relationship
Hotels and Room Relationship
Signup and view all the flashcards
Customer and Vehicle Classes relation
Customer and Vehicle Classes relation
Signup and view all the flashcards
Attraction Table
Attraction Table
Signup and view all the flashcards
Street Table
Street Table
Signup and view all the flashcards
Hotel and Meeting Room relation
Hotel and Meeting Room relation
Signup and view all the flashcards
Country and Alliance Multiplicity
Country and Alliance Multiplicity
Signup and view all the flashcards
Employe eligibility modeled
Employe eligibility modeled
Signup and view all the flashcards
Rental attributes
Rental attributes
Signup and view all the flashcards
Study Notes
Quiz 1: SQL Focus
SELECT * FROM staff ORDER BY lastname ASC
lists staff details with those having last names alphabetically at the beginning of the list.SELECT name FROM course WHERE level IN (3, 4) AND credits > 10 AND semester != 2
finds courses at level 3 or 4 with more than 10 credits, excluding semester 2.SELECT lastname FROM staff WHERE phone IS NULL OR office IS NULL
identifies staff members who have a missing phone number or office number.SELECT bc, name FROM allmarks17, course WHERE allmarks17.bc = course.bc
finds courses taken by students in 2017 by joining theallmarks17
table with thecourse
table.SELECT name FROM course WHERE bc IN (SELECT bc FROM allmarks17) AND cid NOT IN (SELECT cid FROM lecturing WHERE year = 2017)
lists courses with exams taken in 2017 but not taught in 2017.SELECT lastname FROM staff WHERE phone IS NOT NULL EXCEPT SELECT lastname FROM staff WHERE office IS NOT NULL
finds staff with a phone number but no office number.SELECT cid FROM lecturing WHERE year = 2015 AND cid NOT IN (SELECT cid FROM lecturing WHERE year < 2015)
lists courses new in 2015 that were not taught earlier.SELECT cid, AVG(numbers), COUNT(DISTINCT sid) FROM lecturing GROUP BY cid
lists average enrollment numbers and distinct staff count for coursesSELECT cid, year FROM lecturing GROUP BY cid, year HAVING COUNT(*) > 1
finds courses repeated in the same year.SELECT COUNT(DISTINCT student), COUNT(DISTINCT bc) FROM allmarks17
computes the number of distinct students and courses inallmarks17
.SELECT bc, AVG(CASE WHEN year = 2016 THEN mark END), AVG(CASE WHEN year = 2017 THEN mark END) FROM allmarks WHERE year IN (2016, 2017) GROUP BY bc HAVING COUNT(DISTINCT year) = 2
lists courses with average marks for both 2016 and 2017.SELECT lastname FROM staff WHERE sid NOT IN (SELECT sid FROM lecturing)
lists staff who did not lecture.
Quiz 2: SQL & Relational Algebra Focus
SELECT name, COUNT(student), AVG(mark), MAX(mark), MIN(mark), STDDEV(mark) FROM course, allmarks18 WHERE course.bc = allmarks18.bc GROUP BY name ORDER BY name
shows course statistics (count of students, average mark, max mark, min mark, standard deviation of mark) ordered by name.SELECT s1.lastname FROM staff s1, staff s2 WHERE s1.office = s2.office AND s1.sid != s2.sid
finds staff members who share an office, using a self join to compare staff records.- The relational algebra expression σ_{D=p}(π_{X,Y}(T1) ⋈ π_{X,D}(T2)) results in 2 tuples, after projecting, joining, and filtering.
- π_{name}(σ_{lastname='Jung' ∧ (year=2013 ∨ year=2014)}(staff ⋈ lecturing ⋈ course)) relational algebra expression retrieves the names of staff members with the last name 'Jung' who lectured in either 2013 or 2014 and joins
staff
,lecturing
, andcourse
tables. SELECT l1.cid FROM lecturing l1, lecturing l2 WHERE l1.cid = l2.cid AND l1.year = 2016 AND l2.year = 2017 AND l1.numbers < l2.numbers
lists the courses with increased enrollment from 2016 to 2017 by comparing the number of students enrolled in the same course in those years.SELECT bc, COUNT(CASE WHEN mark < 40 THEN 1 END) / COUNT(*)::FLOAT FROM allmarks18 GROUP BY bc
calculates the hard-failure rate for courses inallmarks18
.- π_{lastname}(σ_{numbers > 100}(staff ⋈ lecturing)) returns the last names of staff teaching courses with over 100 students through joining the
staff
andlecturing
tables. SELECT name FROM lecturing, course WHERE lecturing.cid = course.cid AND numbers > 100 EXCEPT SELECT name FROM course WHERE level = 1
SQL query matches the relational algebra expression π_{name}(σ_{numbers > 100}(lecturing ⋈ course)) - π_{name}(σ_{level=1}(course)).- The natural inner join of tables T1 and T2 results in 2 tuples.
- The natural full outer join of tables T1 and T2 results in 7 tuples.
Quiz 3: ER Modeling & Logical Design Focus
- In a tourist information system, the multiplicity between City and County is (1,1) from City to County, and (0,many) from County to City.
- For a hotel database, the Room relationship to Accommodation is best described as a weak entity with a (1,many) relationship to Accommodation.
- In a car rental system, the multiplicity between Customer and Vehicle Class is (0,many) both ways.
- The schema that correctly represents the Attraction table is Attraction(attraction_id, name, city_id°, street_id).
CREATE TABLE Street (street_id INT PRIMARY KEY, name VARCHAR(50), length INT, city_id INT REFERENCES City(city_id) ON DELETE CASCADE)
is the SQL CREATE statement thatmatches the Street table.- In the hotel system, the multiplicity between Hotel and Meeting Room is (0,many) from Hotel to Meeting Room, and (1,1) from Meeting Room to Hotel.
- In the UN system, the multiplicity between Country and Alliance is (0,many) both ways.
- In the car rental system, Employee eligibility is modeled as a relationship between Commercial Customer and Employee.
- The Rental table is represented by the schema Rental(rental_id, customer_id, vehicle_id, class, start_date, end_date).
- The Commercial Customer’s eligible Employees is represented by the schema Eligible(customer_id, employee_id).
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.