w3resource

SQL SORTING and FILTERING on HR Database: Display job ID for those jobs that were done by two or more for more than 300 days

SQL SORTING and FILTERING on HR Database: Exercise-24 with Solution

24. From the following table, write a SQL query to find each job ids where two or more employees worked for more than 300 days. Return job id.

Sample table : job_history


Sample Solution:

SELECT job_id 
	FROM job_history 
		WHERE end_date-start_date >300 
			GROUP BY job_id 
				HAVING COUNT(*)>=2;

Sample Output:

   job_id
------------
 AC_ACCOUNT
 ST_CLERK
(2 rows)

Relational Algebra Expression:

Relational Algebra Expression: Display job ID for those jobs that were done by two or more for more than 300 days.

Relational Algebra Tree:

Relational Algebra Tree: Display job ID for those jobs that were done by two or more for more than 300 days.

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display job ID for those jobs that were done by two or more for more than 300 days - Duration

Rows:

Query visualization of Display job ID for those jobs that were done by two or more for more than 300 days - Rows

Cost:

Query visualization of Display job ID for those jobs that were done by two or more for more than 300 days - Cost

Contribute your code and comments through Disqus.

Previous: From the following table, write a SQL query to count the number of employees, sum of all salary, and difference between the highest salary and lowest salary by each job id. Return job_id, count, sum, salary_difference.
Next: From the following table, write a SQL query to count the number of cities in each country has. Return country ID and number of cities.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

MySQL export schema without data

mysqldump -h yourhostnameorIP -u root -p --no-data dbname > schema.sql

Ref: https://bit.ly/3xzB9dS