w3resource

AdventureWorks Database: Records of employees, order on hiredate

SQL Query - AdventureWorks: Exercise-30 with Solution

30. From the following table write a query in SQL to retrieve records of employees. Order the output on year (default ascending order) of hiredate. Return BusinessEntityID, JobTitle, and HireDate.

Sample table: HumanResources.Employee


Click to view Full table

Sample Solution:

SELECT BusinessEntityID, JobTitle, HireDate  
FROM HumanResources.Employee  
ORDER BY DATE_PART('year',HireDate);

Sample Output:

businessentityid|jobtitle                                |hiredate  |
----------------+----------------------------------------+----------+
              28|Production Technician - WC60            |2006-06-30|
              17|Marketing Assistant                     |2007-01-26|
              16|Marketing Manager                       |2007-12-20|
               3|Engineering Manager                     |2007-11-11|
              40|Production Supervisor - WC60            |2007-12-26|
               4|Senior Tool Designer                    |2007-12-05|
              12|Tool Designer                           |2007-12-11|
             194|Production Technician - WC40            |2008-12-12|
             193|Production Technician - WC40            |2008-12-06|
             188|Production Technician - WC45            |2008-12-27|
             187|Production Technician - WC45            |2008-12-09|
              93|Production Supervisor - WC50            |2008-12-27|
              94|Production Technician - WC50            |2008-12-12|
              95|Production Technician - WC50            |2008-12-19|
             235|Human Resources Manager                 |2008-12-06|
             228|Maintenance Supervisor                  |2008-12-14|
              42|Production Technician - WC60            |2008-12-27|
			  ...

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Fetch result set on an unspecified column.
Next: Retrieve persons last name begins with R.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

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