w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display the ID for those employees who did two or more jobs in the past

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

22. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.

Sample table : job_history


Sample Solution:

SELECT employee_id 
	FROM job_history 
		GROUP BY employee_id 
			HAVING COUNT(*) >=2;

Sample Output:

 employee_id
-------------
         101
         176
         200
(3 rows)

Practice Online


HR database model
HR database model

Query Visualization:

Duration:

Query visualization of Display the ID for those employees who did two or more jobs in the past - Duration

Rows:

Query visualization of Display the ID for those employees who did two or more jobs in the past - Rows

Cost:

Query visualization of Display the ID for those employees who did two or more jobs in the past - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.
Next: Write a query in SQL to display job ID, number of employees, sum of salary, and difference between highest salary and lowest salary for a job.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming