If you have any doubts, please give me comment...
-- a
SELECT *
FROM customer
WHERE cust# IN(
SELECT cust#
FROM order
);
-- b
SELECT *
FROM customer
WHERE cust# IN(
SELECT cust#
FROM order
GROUP BY cust#
HAVING COUNT(*)>1
);
-- c
SELECT *
FROM customer
WHERE cust# IN(
SELECT cust#
FROM order O, salesperson S
WHERE O.emp# = S.emp# AND name = 'Scott Tiger'
);
-- d
SELECT *
FROM customer
WHERE cust# IN(
SELECT cust#
FROM order O, salesperson S
WHERE O.emp# = S.emp# AND name = 'Scott Tiger'
GROUP BY cust#
HAVING COUNT(*)>1
);
-- e
SELECT name, S.emp#
FROM salesperson S, order O, customer C
WHERE S.emp# = O.emp# AND O.cust# = C.cust# AND C.industry_type = 'ABERNATHY CONSTRUCTION'
ORDER BY S.emp# ASC;
-- f
SELECT emp#, COUNT(*) AS noOfOrders
FROM order
GROUP BY emp#;
3. Consider the following relations: salesperson(emp#, name, age, salary); key is emp# order(order#, cust#, emp#, amount);...
Consider the following three relations: TRAVEL_AGENT (name, age, salary) CUSTOMER (name, departure_city, destination, journey_class) TRANSACTION (number, cust_name, travel_agent_name, amount_paid) Write SQL statements to answer the following questions. 1. Display the names and salaries of all travel agents who did not arrange journeys for customer “John Smith”, in ascending order of salary. 2. Display the names of travel agents who have five or more transactions. 3. Display the names of all travel agents who have arranged at least ten journeys to...
Consider the following three relations: TRAVEL_AGENT (name, age, salary) CUSTOMER (name, departure_city, destination, journey_class) TRANSACTION (number, cust_name, travel_agent_name, amount_paid) Write SQL statements to answer the following questions. Compute the number of different customers who have a transaction. Display the name of the oldest travel agent. List the total number of transactions for each travel agent. Consider only those transactions where the amount paid exceeds 1 000.
DROP TABLE EMPLOYEE;
DROP TABLE JOB;
DROP TABLE EMP;
DROP TABLE EMP_1;
DROP TABLE EMP_2;
CREATE TABLE JOB(JOB_CODE CHAR (3) PRIMARY KEY, JOB_DESCRIPTION
VARCHAR (20) NOT NULL,JOB_CHG_HOUR NUMBER (5,2) NOT
NULL,JOB_LAST_UPDATE DATE NOT NULL);
INSERT INTO JOB
VALUES('500','Programmer','35.75','20-Nov-2017');
INSERT INTO JOB VALUES('501','System
Analyst','96.75','20-Nov-2017');
INSERT INTO JOB VALUES('502','Database
Designer','125.00','24-Mar-2018');
CREATE TABLE EMPLOYEE(EMP_NUM CHAR (3) PRIMARY KEY,EMP_LNAME
VARCHAR (15) NOT NULL,EMP_FNAME VARCHAR (15) NOT NULL, EMP_INITIAL
CHAR (1),EMP_HIREDATE DATE NOT NULL,JOB_CODE CHAR (3), EMP_YEARS
NUMBER (2),FOREIGN KEY (JOB_CODE) REFERENCES JOB (JOB_CODE));
INSERT...
2) Consider the database schema on the relations (where key attributes have been underlined): PROJECTS(Number, Department, ProjectName) EMPLOYEES(Number, Surname, FirstName, Department) ALLOCATIONSEmplovee, Project, Function, Date) NOTE: relation ALLOCATIONS stores the registration number (attribute Employee) of employees that are assigned to a given project (attribute Project is the number of the project, not the name of the project), the function the employee has in that project (i.e., technician, manager, etc.) and the date when the employee has been assigned to that...
SQL Queries 1) Use the following relations to answer the problems below. Person(SSN, Age, Name) Professor(SSN, Rank, Specialty) GraduateStudent(SSN, DegreeProgram, AdvisorSSN, DepartmentNumber) Project Number, StartDate, EndDate, Budget, SponsorOrganizationName) DepartmentNumber, Name, Abbreviation, MainOffice, ChairmanSSN) WorksFor(ProfessorSSN, Department Number, TimePercentage) WorksOn(GraduateStudentSSN, ProjectNumber, SupervisingProfessorSSN) Retrieve the Name and Specialty of all Professors who do not supervise work projects. This solution must meet the following conditions: D a. Uses at most one inner joirn b. Uses at most one outer join cNo subqueries al d....
consider the following schema: Product(pid, name, type, manufacturer, price) key: pid Buys(cid, pid) key: cid and pid together Customer(cid, cname, age, gender) key: cid 1) write the following query in relational algebra; find the names of all customers who have purchased all products manufactured by sears. 2)write the following in sql: find the names of all the customers who have not purchased the most expensive product. 3)write the following query in sql: find the best selling products (in terms of...
consider the following schema: Product(pid, name, type, manufacturer, price) key: pid Buys(cid, pid) key: cid and pid together Customer(cid, cname, age, gender) key: cid 1) write the following query in relational algebra; find the names of all customers who have purchased all products manufactured by sears. 2)write the following in sql: find the names of all the customers who have not purchased the most expensive product. 3)write the following query in sql: find the best selling products (in terms of...
Question 4: E-R Diagrams-(10 marks Draw an E-R Diagram for the following situation: Employees (identified by EMP-ID, SURNAME, FIRST-NAME, and Date-of Birth) make many orders (identified by ORDER-NO, ORDER-DATE, DES, WUOTED-PRICE) for Customers (Identified by CUST-ID). The orders are for one customer at a time but a customer might have many orders. The orders create many requests (Identified by REQUEST-NO, START-DATE, END-DATE). Those requests might result in few jobs (identified by JOB-NO COST) and consequently will use different materials (identified...
Consider the database consisting of the following relations: Flights(Fl#: integer, From: string, To: string, Distance: integer, departs: Time, Arrives: time) Flight Instance(Fl#: integer, Day: date, Aid: Integer) Aircraft(Aid: integer, Make: string, Model: string, CrusingRange: string) Certified(Eid: integer, Make: string, Model: string) Employee(Eid: integer, Ename: string, Salary: integer) Fight Attendant(Fl#: integer, Day: date, Eid:integer, Role: string) The Flight table contains general information about the flights whereas the Flight Instance is about a flight number on a specific date. Aircraft list the...
Consider a database with the following schema. LIKES(drinker,beer); /* key: all columns */ FREQUENTS(drinker,pub); /* key: all columns */ SERVES(pub,beer,cost); /* key: (pub,beer) */ Write the following queries in relational algebra. You can use the math notation (greek letters sigma, pi, etc.) or the ASCii "linear" notation I used in class. In order to make things more clear, please use intermediate results defined with the assignment notation in the algebra: R(a,b) := <rel-alg expression>. Try to give meaningful names for...