Hello need some assistance with the following Oracle SQL statements 7. Create a
ID: 3888529 • Letter: H
Question
Hello need some assistance with the following Oracle SQL statements
7. Create a query that uses a natural join to join the departments table and the employees table by the department_number column. Display all columns.
8. Join Employees, departments, and projects tables with the JOIN USING syntax. Include the employee first and last name, department_name and project_number.
9. Write a statement joining the employees and projects tables. Display the first and last names, department number and manager id. Limit the query to those employees whose project number is P1011 or P1012.
10. Write a statement that displays the employee ID, first name, last name, manager ID, manager first name, and manager last name for every employee in the employees table. Hint: this is a self-join.
11. Query and display manager ID, department number, department name, first name, and last name for all employees in departments 1, 2, and 5.
12. Write a query that returns 3 columns: vendor_name from the vendors table, invoice_date from the invoices table, and balance_due which is invoice_total – payment_total – credit_total from the invoices table. The result set should have one row for each invoice with a non-zero balance. Sort the result set by vendor_name in descending order and by invoice_date in ascending order.
13. Use an outer join for this exercise. Write a query that returns two columns (account number and account description) from the General_Ledger_Accounts table. The result set should have one row for each account number that has never been used. Sort the final result set by account number in descending order.
Explanation / Answer
7.
Select * from departments natural join employees using(department_number);
8.
Select firstname, lastname, department_name ,project_number from employees natural join departments using (department_number) natural join project using(department_number) ;
9.
Select firstname, lastname, department_number ,manager_id from employees natural join departments using (department_number) natural join project using(department_number) where project.project_number = 'P1011' or project.project_number = 'P1012';
10
Select e1.employeeID, e1.firstname, e1.lastname,e1.managerID, e2.firstname, e2.lastname from employee e1 inner join employees e2 on e1.managerID = e2.employeeID;
11.
Select managerID, department.department_number, department_name, firstname, lastname from employees inner join departments on employees.department_number = department.department_number where department_number IN(1,2,5);
12
Select vendor_name,invoice_date ,invoice_total – payment_total – credit_total as balance_due from vendors natural join invoices using(invoice_number) order by vendor_name desc,invoice_date asc;
13
Select Accounts.account_number,Accounts.description from General_Ledger_Accounts right outer join Accounts on General_Ledger.account_number = Accounts.account_number order by Accounts.account_number desc;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.