From the following table, write a SQL query to compute the experience of all the…
- User
From the following table, write a SQL query to compute the experience of all the managers. Return employee ID, employee name, job name, joining date, and experience.
- Assistant
To compute the experience of all the managers, you will need to join the "employees" and "jobs" tables. Assuming the "employees" table has columns "employee_id", "employee_name", "job_id", and "joining_date", and the "jobs" table has columns "job_id" and "job_name", you can use the following SQL query:
sqlSELECT e.employee_id, e.employee_name, j.job_name, e.joining_date, DATEDIFF(CURDATE(), e.joining_date) AS experience FROM employees e JOIN jobs j ON e.job_id = j.job_id WHERE j.job_name = 'Manager'In this query, the DATEDIFF function is used to calculate the experience by subtracting the joining date from the current date (CURDATE()). The result is aliased as "experience". The WHERE clause filters the results to only include managers.
- User
CREATE TABLE employees (emp_id INT PRIMARY KEY,emp_name VARCHAR(15),job_name VARCHAR(10),manager_id INT,hire_date DATE ,salary float,commission float,dep_id INT); INSERT INTO employees (emp_id, emp_name, job_name, manager_id, hire_date, salary, commission, dep_id) VALUES (68319, 'KAYLING', 'PRESIDENT', NULL, '1991-11-18', 6000.00, NULL, 1001), (66928, 'BLAZE', 'MANAGER', 68319, '1991-05-01', 2750.00, NULL, 3001), (67832, 'CLARE', 'MANAGER', 68319, '1991-06-09', 2550.00, NULL, 1001), (65646, 'JONAS', 'MANAGER', 68319, '1991-04-02', 2957.00, NULL, 2001), (67858, 'SCARLET','ANALYST', 65646, '1997-04-19', 3100.00, NULL, 2001), (69062, 'FRANK', 'ANALYST', 65646, '1991-12-03', 3100.00, NULL, 2001), (63679, 'SANDRINE', 'CLERK', 69062, '1990-12-18', 900.00, NULL, 2001), (64989, 'ADELYN', 'SALESMAN', 66928, '1991-02-20', 1700.00, 400.00, 3001), (65271, 'WADE', 'SALESMAN', 66928, '1991-02-22', 1350.00, 600.00, 3001), (66564, 'MADDEN','SALESMAN', 66928, '1991-09-28', 1350.00, 1500.00, 3001), (68454, 'TUCKER', 'SALESMAN', 66928, '1991-09-08', 1600.00, 0.00, 3001), (68736, 'ADNRES', 'CLERK', 67858, '1997-05-23', 1200.00, NULL, 2001), (69000, 'JULIUS', 'CLERK', 66928, '1991-12-03', 1050.00, NULL, 3001), (69324, 'MARKER', 'CLERK', 67832, '1992-01-23', 1400.00, NULL, 1001); From the following table, write a SQL query to compute the experience of all the managers. Return employee ID, employee name, job name, joining date, and experience using this data
- Assistant
To compute the experience of all the managers, you can use the following SQL query with the given data:
sqlSELECT e.emp_id, e.emp_name, e.job_name, e.hire_date, DATEDIFF(CURDATE(), e.hire_date) AS experience FROM employees e WHERE e.job_name = 'MANAGER'This query selects the employee ID, employee name, job name, and joining date from the "employees" table. The DATEDIFF function is used to calculate the experience by subtracting the hire date from the current date (CURDATE()). The result is aliased as "experience". The WHERE clause filters the results to only include employees with the job name 'MANAGER'.