Question

In: Computer Science

PostgreSQL 1. Write a query to join two tables employees and departments to display the department...

PostgreSQL

1. Write a query to join two tables employees and departments to display the department name, first_name and last_name, hire date, and salary for all managers who have more than 15 years of experience.

2. Write a query to join the employees and departments table to find the name of the employee including the name and last name, department ID and department name.

3. Write a SQL query to join three tables of employees, departments, and locations to find the names, including first and last name, job title, department name and ID, of employees working in London.

4. Write a query to concatenate the two tables of employees and yourself to find the employee id, last_name as Employee, and their manager_id and last name as Manager.

5. Write a query to connect to the employee table and to yourself to find the name, including first_name and last_name, and the hiring date for those employees who were hired after employee Jones.

6. Write a query to combine the two employee and department tables to get the department name and the number of employees working in each department.

7. Write a query to find employee ID, title and number of days he worked, who worked in department with ID 90.

8. Write a query to combine the two employee and department tables to display the department ID, department name, and manager name.

Solutions

Expert Solution

1. select dep.department_name,emp.first_name,emp.last_name,emp.hire_date,emp.salary from employees emp join departments dep on emp.employee_id=dep.manager_id where (DATEDIFF(now(),hire_date))/365>15;

2. select (emp.first_name,emp.last_name) as "Name",dep.department_id,dep.department_name from employees emp join departments dep on emp.employee_id=dep.manager_id;

3. select (emp.first_name,emp.last_name) as "Name",emp.job_id,dep.department_id,dep.department_name from employees emp join departments dep on emp.employee_id=dep.manager_id join locations loc using (location_id) where loc.city='LONDON';

4. select emp.employee_id as "Employee_id" , emp.last_name as "Employee", man.employee_id as "Manager ID", man.last_name as "Manager" from employees emp JOIN employees man on emp.employee_id=man.manager_id;

5. select (emp.first_name,emp.last_name) as "Name",emp.hire_date from employees emp join employees davies ON (davies.last_name = 'Jones') where davies.hire_date < emp.hire_date;

6. select department_name as 'Department Name', COUNT(*) as 'No of Employees' from departments JOIN employees ON employees.department_id = departments.department_id GROUP BY departments.department_id, department_name ORDER BY department_name;

7. select employee_id, job_title, (end_date - start_date) as 'No. of Days' FROM job_history natural join jobs WHERE department_id=90;

8. select dep.department_id, dep.department_name, dep.manager_id, emp.first_name from departments dep join employees emp ON (dep..manager_id = emp.employee_id);


Related Solutions

Write a query that returns the department id and the number of employees (in the associated...
Write a query that returns the department id and the number of employees (in the associated department) salary is over $2500 and, at the end, result page has to show only department ids that have more than 5 employees in it. Please Note: (we don't interest all of department ids in our grouping action and also we don’t want to see any kind of total employee number in the result page we want to see limited result set) Hint1: SELECT...
Write a query to display the columns listed below. For each customer the query should show...
Write a query to display the columns listed below. For each customer the query should show the current system date, the current day (when you do the problem the date and day will be different), the number of characters in the member last name, the last date the customer rented a video and how many total videos the person rented. /* Database Systems, 9th Ed., Coronel/MOrris/Rob */ /* Type of SQL : MySQL */ CREATE SCHEMA IF NOT EXISTS TINY_VIDEO;...
1. write SQL statements to create the following two tables: a) Department table that contains the...
1. write SQL statements to create the following two tables: a) Department table that contains the following columns(dept_no,deptname,location) set the deptno to be the primary key. b) Employee table contains the following columns(emp_no,empname,deptno,salary)set the emp_no to be the primary key and dept_no to be the foreign key. 2. Write SQL statements to Insert the following 3 rows in Employee table:        (101,’Sami’,’D-101’,5000)        (102,’Yousef’,’D-101’,4000)        (103,’Sami’,’D-102’,7000) 3. Write SQL statements to Insert the following 3 rows in Department table:       ...
Write a SELECT statement that returns these columns using a JOIN of three tables: order_date from...
Write a SELECT statement that returns these columns using a JOIN of three tables: order_date from the orders table shipped_date from the orders table order_qty from the order_details table title from the items table artist from the items table unit_price from the items table Result table should be in order of order_date in ascending order
QUERY PROCESSING JOIN 1) Let the schema of a relation r as R(A,B,C), and a relation...
QUERY PROCESSING JOIN 1) Let the schema of a relation r as R(A,B,C), and a relation s has schema S(C,D,E). Relation table r has 40K tuples, relation s has 60K tuples. The block factor of r is 25. The block factor of s is 30. Let the average seek time is t S and average block transfer time is t T . Assume you have a memory that contains M pages, but M< 40K/25 (indicating that s cannot be entirely...
Create a query in Access that uses two tables, the Patient table and the Session table. Add
Create a query in Access that uses two tables, the Patient table and the Session table. Add the LastName, FirstName, and SessionDate fields to the query grid. Run the query. How many records are displayed? Delete the join line between the field lists in Query Design View. Rerun the query. How many records are now displayed? Why are the results different? You do not need to save the queries. 
Problem 44 Write a query to display the employee number, last name, first name, and sum...
Problem 44 Write a query to display the employee number, last name, first name, and sum of invoice totals for all employees who completed an invoice. Sort the output by employee last name and then by first name (Partial results shown in Figure P7.44).
Matt limited has two production, departments, machine department and assembly department. There are two service departments,...
Matt limited has two production, departments, machine department and assembly department. There are two service departments, stores and maintenance. The budgeted overheads of each department along with overheads that have yet to be apportioned are listed below, along with details which can be used for appointment. Total Machine Dept Assembly Dept Stores Maintenance K’000 K’000 K’000 K’000 K’000 Indirect labour 1 125 000 400 000 650 000 40 000 35 000 Indirect material 310 000 160 000 120 000 10...
1. Brownley Company has two service departments and two operating (production) departments. The Payroll Department services...
1. Brownley Company has two service departments and two operating (production) departments. The Payroll Department services all three of the other departments in proportion to the number of employees in each. The Maintenance Department costs are allocated to the two operating departments in proportion to the floor space used by each. Listed below are the operating data for the current period: Service Depts. Production Depts. Payroll Maintenance Cutting Assembly Direct costs $ 32,400 $ 37,500 $ 88,500 $ 117,400 No....
1- Use FirstLastList: Write method public void join(FirstLastList SecondList) such that given two linked lists, join...
1- Use FirstLastList: Write method public void join(FirstLastList SecondList) such that given two linked lists, join them together to give one. So if the lists lst1= [1,3,7,4] and lst2=[2,4,5,8,6], the result of lst1.join(lst2) is lst1=[1,3,7,4,2,4,5,8,6] and lst2=[]. 2- Use FirstLastList: Write method public void swap(). It swaps the first and last elements of a FirstLastList. So if lst1= [1,3,7,4], lst1.swap() = [4,3,7,1]. Display or throw an exception if the list contains less than two elements. Demonstrate by displaying the list...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT