Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Divide-and-Conquer for Multi-Unit Queries Query Condition To decide whether a given query requirement is single- unit or multi-unit, we need to find its query

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
2. Divide-and-Conquer for Multi-Unit Queries Query Condition To decide whether a given query requirement is single- unit or multi-unit, we need to find its query condition first. Query condition is the part of the query requirement that specifies what rows should be kept in the query result. In English grammar, this is often the adjective clause of a sentence. For example, if the query requirement is to find the names of the programs that are offered by departments whose IDs are 'CS' and EE then the query condition is the underlined part of the sentence. Note that when a query requirement does not have a query condition, it is a single-unit query. (1) Query: Find all faculty members who work for the department with ID 'CS'. .) Does the query have a query condition? If yes, what is the query condition? Answer: 2) Query: Find names and GPAs of all students. a) Does the query have a query condition? If yes, what is the query condition? Answer: (3) Query: For students majoring in the program with ID 'P000', return their names and GPAs. a) Does the query have a query condition? If yes, what is the query condition? Answer: Keywords in Query Condition to Recognize Multi-unit Queries Once we find the query condition in the query requirement (assuming there is one), we will check for the existence of one or more keywords in the query condition. For now, we only consider the following keywords: AND, OR and NOT. If any of the keywords is found in the query condition, then the query is multi- unit. Otherwise, it is single unit. (1) Query: Return records of all faculty members who work for the department with ID 'CS'. a) Is the query multi-unit? Why or why not? Answer: (2) Query: Return program IDs of those degree programs offered by both 'CS' and 'EE' departments. Note that 'CS' and 'EE' are department IDs. a) Is the query multi-unit? Why or why not? Answer: (3) Query: Return names and GPAs of all students. a) Is the query multi-unit? Why or why not? Answer: (4) Query: For students majoring in program ID 'P000' or 'P001', return their names. a) Is the query multi-unit? Why or why not? Answer: Divide-and-Conquer Query Construction Once we have recognized a multi-unit query, we can use the divide-and-conquer method to construct it. First, based on the keyword found in the query condition, we divide the original query requirement into multiple single-unit queries. We can then construct the single-unit queries separately using the method presented in Section 1 Constructing Single Unit Queries. After the single-unit queries are constructed, they can be combined using the set operator corresponding to the keywords found in the query condition: set intersect (c) for AND, set union () for OR, and set difference (-) for NOT (1) Query: Return the names of the departments whose addresses are 'MCS' or 'HOH'. a) In plain English, write down the first query unit. Answer: b) In plain English, write down the second query unit. Answer: c) What should be the set operator to combine the first and second query units. Answer: .) Based on your answers above, provide the complete query statement. You can write it as a relational algebraic expression or SQL command. Answer: (2) Query: For students majoring programs named 'Comp Sci' or 'Soft Engr', return their snames. a) In plain English, write down the first query unit. Answer: b) In plain English, write down the second query unit. Answer: (3) Query: Return the names of those degree programs that are offered by the 'CS' department but not by the 'EE' department. Note that 'CS' and 'EE' are department IDs. a) In plain English, write down the first query unit. Answer: b) In plain English, write down the second query unit. Answer: c) What should be the set operator to combine the first and second query units. Answer: d) Based on your answers above, provide the complete query statement. You can write it as a relational algebraic expression or SQL command

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions