Sorting in order of days of birth |
||||||||||||||||||
Such a sorting may be useful for getting the order of celebration of employees' DOB. Let's consider the Battles table as an example, namely date column. It is evident that ordering by date does not required result due to the year (for example, October 20 follows after November 15):
To solve the problem, two methods can be suggested (in SQL(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL Server dialect). 1. Use of CONVERT functionIn so doing, we transform datetime value to the string representation in the format "mm-dd"
2. Use of MONTH and DAY functionsHere we use built-in functions which return date components - month (MONTH) and day (DAY) respectively. Let's do sorting on these components: As regards query performance, you can choose any method because optimizer produces identical execution plans for these. Finally let's give the last query in a more presentable form having included in it additionally a "hero of the festivities":
|