Question

In: Computer Science

A database schema consisting of three relations STUDENT, COURSE, and STAFF is created as follows: CREATE...

A database schema consisting of three relations STUDENT, COURSE, and STAFF is created as follows:

CREATE TABLE STUDENT (STU_ID CHAR(4),

STUDENT_NAME CHAR(20),

ADDRESS CHAR(20),

BIRTHDATE DATE,

GENDER CHAR(6));

CREATE TABLE COURSE (COURSE_ID CHAR(6),

COURSE_TITLE CHAR(20),

STAFF_ID CHAR(3),

SECTION NUMBER(2));

CREATE TABLE STAFF (STAFF_ID CHAR(3),

STAFF_NAME CHAR(20),

GENDER CHAR(6),

DEPARTMENT CHAR(20),

BOSS_ID CHAR(3)

SALARY NUMBER(8,2));

Write down SQL statement for each query below:

1) Find out the information of staff members who are female and earn either below $5,000 or above $30,000. [5 marks] 2) List all staff members who are not in the Accounting nor the History department. [5 marks] 3) List all students whose name contains the substring "JONES". List the females before the males in chronological order (by birthdate). [6 marks] 4) List all the courses taught by Raymond J. JOHNSON. [6 marks] 5) Find the names of all staff members who earn more than their bosses. [8 marks] 6) List all staff members who are either in the same department as Amy Dancer or Jack Nelson. [8 marks] 7) Find the names of the staff members who make more money than every member of the Accounting department. [7 marks] 8) Find the average salary for each department with more than one staff member. [5 marks]

Solutions

Expert Solution

Question 1:

SELECT * FROM STAFF WHERE GENDER="Female" AND (SALARY NUMBER<5000 OR SALARY NUMBER>30000).

Here, assuming the salary number entries are in dollars and gender entries are either Male or Female, the query is as above. If the entries are different you can modify it as per the entries. But the basic structure is the same.

Question 2:

SELECT STAFF_NAME FROM STAFF WHERE NOT DEPARTMENT="Accounting" AND NOT DEPARTMENT="History"

Assuming to print the staff names, the query is as stated above. If you want the complete details of the staff please use * instead of staff_name.

Question 3:

SELECT STUDENT_NAME FROM STUDENT WHERE STUDENT_NAME LIKE '%JONES%' GROUP BY GENDER ORDER BY BIRTHDATE

This query prints all the student names having jones as a substring and females first and males next by ordering the birthdays in ascending order or chronological order.

Question 4:

SELECT COURSE_TITLE FROM COURSE WHERE STAFF_ID IN (SELECT STAFF_ID FROM STAFF WHERE STAFF_NAME="Raymond J.JOHNSON")

Question 5:

Information is not sufficient. Boss salary is not obtained from the above 3 tables.

Question 6:

SELECT STAFF_NAME FROM STAFF WHERE DEPARTMENT IN (SELECT DEPARTMENT FROM STAFF WHERE STAFF_NAME="Amy Dancer" OR STAFF_NAME = "Jack Nelson")

Question 7:

SELECT STAFF_NAME FROM STAFF WHERE SALARY NUMBER > ALL(SELECT SALARY NUMBER FROM STAFF WHERE DEPARTMENT="Accounting")

Question 8:

SELECT DEPARTMENT, avg(SALARY NUMBER) as AverageSalary FROM STAFF GROUP BY DEPARTMENT HAVING count(STAFF_ID)>1

Please feel free to comment in the comment section for any clarifications.


Related Solutions

• Relational Schema Create a relational database schema consisting of the four relation schemas representing various...
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various entities recorded by a furniture company.   Write CREATE TABLE statements for the following four relation schemas. Define all necessary attributes, domains, and primary and foreign keys. Customer(CustomerID, Name, Address) FullOrder(OrderID, OrderDate, CustomerID) Request(OrderID, ProductID, Quantity) Product(ProductID, Description, Finish, Price) You should assume the following: Each CustomerID is a number with at most three digits, each OrderID is a number with at most five digits,...
The schema for the Academics database is as follows. Understanding this schema is necessary to answer...
The schema for the Academics database is as follows. Understanding this schema is necessary to answer the questions in Part B. DEPARTMENT(deptnum, descrip, instname, deptname, state, postcode) ACADEMIC(acnum, deptnum*, famname, givename, initials, title) PAPER(panum, title) AUTHOR(panum*, acnum*) FIELD(fieldnum, id, title) INTEREST(fieldnum*, acnum*, descrip) The semantics of most attributes are self-explanatory. For each relation, the primary key is underlined and any foreign keys are denoted by an asterisk (*). Some additional information for relations is given below: DEPARTMENT: Each academic department...
Given the same simple Employee-Workson-Project database schema , which contains three files described as follows:
Given the same simple Employee-Workson-Project database schema , which contains three files described as follows:Emp (eid : integer, ename : string, age : integer, salary: real)Workson (eid : integer, pid : integer, hours : integer)Project (pid : integer, pname : string, budget : real, managerid : integer)Note : eid, ename, age and salary are the employee id, name, age and salary respectively. Also, hours is the number of hours worked by employee on a project. The rest of the attributes...
Discuss the three-schema architecture and its benefits for database development and design.
Discuss the three-schema architecture and its benefits for database development and design.
Create a schema file that captures the requirements for a <student> element> Here are the specifications...
Create a schema file that captures the requirements for a <student> element> Here are the specifications for student: 3.1. A student must have a first name and last name. 3.2. A student may have a middle name, but it’s optional. 3.3. A student may have a home address, a work address, or both.             3.3.1. Use a complex type to connect to a single schema definition for “address” 3.4. An address has: a street address, city, state, and zip code....
Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and...
Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and the one-to-one or one-to-many relationships between the tables. Also describe in a small paragraph the scope of the back-end database, by explaining the different tables and their relations in your schema.
Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection...
Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection of attributes for each of the entities. Make sure you use the appropriate naming conventions to name the attributes.)
Database - SQL - Operations CS 203 Discrete Structure 2 Create a Microsoft Access Database consisting...
Database - SQL - Operations CS 203 Discrete Structure 2 Create a Microsoft Access Database consisting of the following two tables: Part_needs and Parts_Inventory Part_needs Supplier Part_number Project 23 1092 1 23 1101 3 23 9048 4 31 4975 3 31 3477 2 32 6984 4 32 9191 2 33 1001 1 Parts_Inventory Part_number Project Quantity Color_code 1001 1 14 8 1092 1 2 2 1101 3 1 1 3477 2 25 2 4975 3 6 2 6984 4 10...
Student Structure Assignment Create a Student Structure globally consisting of student ID, name, completed credits, and...
Student Structure Assignment Create a Student Structure globally consisting of student ID, name, completed credits, and GPA. Define one student in main() and initialize the student with data. Display all of the student’s data on one line separated by tabs. Create another student in main(). Assign values to your second student (do not get input from the user). Display the second student’s data on one line separated by tabs. Create a third student in main(). Use a series of prompts...
Design Of Database System Course True or False 1. In MySQL, it is possible to create...
Design Of Database System Course True or False 1. In MySQL, it is possible to create a table by using the definition of another table. 2. {(t.lname) | s ∈ Student, s.stuId = t.stuId, t ∉ Graduate_Student, s.major = ‘CS’} is a safe relational calculus expression. 3. In SQL, it is possible to insert multiple rows into a table using a single INSERT statement.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT