Write SQL Queries Given the following tables
If you have any doubts, please give me comment...
-- Retrieve the names of employees and their project name. If the employee never worked on a project, show the names only the name, not the project name.
SELECT ENAME, PNAME
FROM EMP LEFT OUTER JOIN WORK_ON ON EMP.EMPNO = WORK_ON.EMPNO INNER JOIN PRJ
ON WORK_ON.PRJNO = PRJ.PRJNO;
-- Retrieve the names of employees who have worked on the same project at a different location.
SELECT ENAME
FROM EMP, WORK_ON AS W1, WORK_ON AS W2
WHERE EMP.EMPNO = W1.EMPNO AND EMP.EMPNO = W2.EMPNO AND W1.PRJNO = W2.PRJNO AND W1.LOC<>W2.LOC;
-- Retrieve the names of employees who have worked on more than two different projects.
SELECT ENAME
FROM EMP, WORK_ON
WHERE EMP.EMPNO = WORK_ON.EMPNO
GROUP BY EMP.EMPNO, ENAME
HAVING COUNT(DISTINCT PRJNO)>2;
-- Retrieve the names of employees who manage more than two employees.
SELECT M.ENAME
FROM EMP AS E, EMP AS M
WHERE E.MGR = M.EMPNO
GROUP BY E.MGR, M.ENAME
HAVING COUNT(*)>2;
Write SQL Queries Given the following tables (7pts) Retrieve the names of employees and their project...
Create an XML document for the Oracle Starter Database Tables (i.e., emp, dept, ord, product, price). Each XML document must be in the format as described in the "Mapping tables to XML" section on pg. 1161 (any column that does not have a value can be displayed as empty, e.g., <DEGREE></DEGREE> ). The name for each document will be the name of the table followed by ".xml" as the file extension (e.g., "emp.xml"). Data for dept. table CREATE TABLE DEPT...
1. Create a new table called EmpDB based on emp table but includes only fields: emp mgr, copy data of employees. 2. Create a new table called device that has the following Field name No Name ESSN Data type size Note Number 3 Varchar2 10 Number4 PK 3. Make sure that ID in device table is between 100 and 999. 4. Make the field ESSN in table device as foreign key to the empno in table EmpDB. 5. Create stored...
Lesson 10Create the DEPARTMENT tables based on the following: Column Name ID Name Data Type Number Varchar2 Length 7 25 Populate the DEPARTMENT table with data from the DEPT table. Include only columns that you need. Create the EMPLOYEE table based on the following table chart: Column Name ID LAST_NAME FIRST_NAME DEPT_ID Data Type Number Varchar2 Varchar2 Number Length 7 25 25 7 Modify the EMPLOYEE table to allow for longer employee last names. Confirm your modification. Confirm that both the...
CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT INTO DEPT VALUES (10,'SPORTS','NEW YORK'); INSERT INTO DEPT VALUES (20,'HOME','DALLAS'); INSERT INTO DEPT VALUES (30,'OUTDOOR','CHICAGO'); INSERT INTO DEPT VALUES (40,'CLOTHING','BOSTON'); CREATE TABLE EMP ( EMPNO INTEGER NOT NULL, ENAME VARCHAR(10), JOB VARCHAR(9), MGR INTEGER, SAL FLOAT, COMM FLOAT, DEPTNO INTEGER NOT NULL, FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO), FOREIGN KEY (MGR) REFERENCES EMP(EMPNO), PRIMARY KEY (EMPNO)); INSERT INTO EMP VALUES (7839,'KING','PRESIDENT',NULL, 5000,NULL,10); INSERT INTO...
Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that begins with the letter 'M! CREATE TABLE Persons Personi int LastName varchar(80). FirstName varchar(80). Address varchar(125). State char(2) Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that does not contain the letter 'S: CREATE TABLE Persons PersonlDint,...
Please help me on the SQL queries, thank you so much. Write a query to display the title and publisher as well as the publisher contact for each book using JOIN...USING clause. Write a query to show the first and last names of customers who have ordered cooking books. Use the WHERE clause to join the tables. Write a query to show the title, cost and ISBN of each book in the books table. If the book has been ordered,...
- Consider the following relational schema. - Write SQL statements for the following queries employee fname CHARACTER VARYING (15) minit CHARACTER VARYING(1) InameCHARACTER VARYING(15) essn CHARACTERO) bdate DATE address CHARACTER VARYING(50) dependent works on CHARACTERO dependent name CHARACTER VARYING(15) essn CHARACTER(9) pno NUMERIC hours NUMERIC CHARACTER() DATE CHARACTER VARYING(B) bdate CHARACTER(1) dept locations elationship salary NUMERIC super ssn CHARACTERO) dno dno NUMERIC dlocation CHARACTER VARYING(15) NUMERIC department CHARACTER VARYING(25) NUMERIC CHARACTERO) project dno mgssn mgstartdate DATE pname CHARACTER VARYING(25) pno...
SQL queries and procedures TABLE: Employees Business Rules: EmployeeID is defined as the primary key. Address has been denormalized to include City and State for performance reasons. DeptNbr is a foreign key that references DeptNbr in the Department table Manager is a foreign key that references EmployeeID in the Employees table Data Structure: (EmployeeId, LastName, FirstName, Street, City, State, Zip, DateOfHire, DateOfBirth, JobTitle, Salary, DeptNbr(fk), Manager(fk)) TABLE: Department Business Rules: DeptNbr is defined as the primary key. Data Structure: (DeptNbr,...
database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED BELOW CREATE TABLE Department ( DECIMAL(5) VARCHAR(30) CHAR(5) DATE NOT NULL NOT NULL NOT NULL * Department number /*Department name * Department manager number */ /Manager start date DNumber DName Manager MSDate CONSTRAINT Department_PK PRIMARY KEY(DNumber) CONSTRAINT Department_CK UNIQUE(DName) CREATE TABLE DeptLocation DECIMAL(5) VARCHAR(50) NOT NULL NOT NULL DNumber * Department number */ * Department location */ Address CONSTRAINT DeptLocation_PK PRIMARY KEY(DNumber, Address) CONSTRAINT...
-- echo Building demo tables. Please wait. DROP TABLE EMP CASCADE CONSTRAINTS; DROP TABLE DEPT; DROP TABLE SALGRADE; DROP TABLE Prod CASCADE CONSTRAINTS; DROP TABLE Vend; CREATE TABLE DEPT ( DEPTNO NUMBER(2) NOT NULL, DNAME CHAR(14), LOC CHAR(13), CONSTRAINT DEPT_PRIMARY_KEY PRIMARY KEY (DEPTNO)); INSERT INTO DEPT VALUES (10,'ACCOUNTING','NEW YORK'); INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS'); INSERT INTO DEPT VALUES (30,'SALES','CHICAGO'); INSERT INTO DEPT VALUES (40,'OPERATIONS','BOSTON'); CREATE TABLE EMP ( EMPNO NUMBER(4) NOT NULL, ENAME CHAR(10), JOB CHAR(9), MGR NUMBER(4) CONSTRAINT EMP_SELF_KEY...