w3resource

MySQL String Exercises: Display the employees with their code, first name, last name and hire date who hired either on seventh day of any month or seventh month in any year

MySQL String: Exercise-17 with Solution

Write a query to display the employees with their code, first name, last name and hire date who hired either on seventh day of any month or seventh month in any year.

Sample table: employees


Code:

SELECT employee_id,first_name,last_name,hire_date 
FROM employees 
WHERE POSITION("07" IN DATE_FORMAT(hire_date, '%d %m %Y'))>0;

Sample Output:

employee_id	first_name	last_name		hire_date
114		Den		Raphaely		1987-07-01T04:00:00.000Z
115		Alexander	Khoo			1987-07-02T04:00:00.000Z
116		Shelli		Baida			1987-07-03T04:00:00.000Z
117		Sigal		Tobias			1987-07-04T04:00:00.000Z
118		Guy		Himuro			1987-07-05T04:00:00.000Z
119		Karen		Colmenares		1987-07-06T04:00:00.000Z
120		Matthew		Weiss			1987-07-07T04:00:00.000Z
121		Adam		Fripp			1987-07-08T04:00:00.000Z
122		Payam		Kaufling		1987-07-09T04:00:00.000Z
123		Shanta		Vollman			1987-07-10T04:00:00.000Z
124		Kevin		Mourgos			1987-07-11T04:00:00.000Z
125		Julia		Nayer			1987-07-12T04:00:00.000Z
126		Irene		Mikkilineni		1987-07-13T04:00:00.000Z
127		James		Landry			1987-07-14T04:00:00.000Z
128		Steven		Markle			1987-07-15T04:00:00.000Z
129		Laura		Bissot			1987-07-16T04:00:00.000Z
130		Mozhe		Atkinson		1987-07-17T04:00:00.000Z
131		James		Marlow			1987-07-18T04:00:00.000Z
132		TJ		Olson			1987-07-19T04:00:00.000Z
133		Jason		Mallin			1987-07-20T04:00:00.000Z
134		Michael		Rogers			1987-07-21T04:00:00.000Z
135		Ki		Gee			1987-07-22T04:00:00.000Z
136		Hazel		Philtanker		1987-07-23T04:00:00.000Z
137		Renske		Ladwig			1987-07-24T04:00:00.000Z
138		Stephen		Stiles			1987-07-25T04:00:00.000Z
139		John		Seo			1987-07-26T04:00:00.000Z
140		Joshua		Patel			1987-07-27T04:00:00.000Z
141		Trenna		Rajs			1987-07-28T04:00:00.000Z
142		Curtis		Davies			1987-07-29T04:00:00.000Z
143		Randall		Matos			1987-07-30T04:00:00.000Z
144		Peter		Vargas			1987-07-31T04:00:00.000Z
151		David		Bernstein		1987-08-07T04:00:00.000Z
182		Martha		Sullivan		1987-09-07T04:00:00.000Z

MySQL Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous:Write a query to display the first eight characters of the employees' first names and indicates the amounts of their salaries with '$' sign. Each '$' sign signifies a thousand dollars. Sort the data in descending order of salary.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.