Advertisement
desislava_topuzakova

Built-in Functions

Jun 25th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # 1. Find Names of All Employees by First Name
  2. SELECT `first_name`, `last_name` from `employees`
  3. WHERE `first_name` LIKE 'Sa%'
  4. ORDER BY `employee_id`;
  5.  
  6. # 2. Find Names of All Employees by Last Name
  7. SELECT `first_name`, `last_name` from `employees`
  8. WHERE `last_name` LIKE '%ei%'
  9. ORDER BY `employee_id`;
  10.  
  11. # 3. Find First Names of All Employees
  12. SELECT `first_name` from `employees`
  13. WHERE `department_id` IN (3,10)
  14. AND
  15. year(`hire_date`) BETWEEN 1995 and 2005
  16. ORDER BY `employee_id`;
  17.  
  18. # 4. Find All Employees Except Engineers
  19. SELECT `first_name`, `last_name` from `employees`
  20. WHERE `job_title` NOT LIKE '%engineer%'
  21. ORDER BY `employee_id`;
  22.  
  23. # 5. Find Towns with Name Length
  24. SELECT `name` from `towns`
  25. WHERE char_length(`name`) = 5 OR char_length(`name`) = 6
  26. ORDER BY `name`;
  27.  
  28. # 6. Find Towns Starting With
  29. SELECT * FROM `towns`
  30. WHERE `name` LIKE ('m%') OR `name` LIKE ('k%') OR `name` LIKE ('b%') OR `name` LIKE ('e%')
  31. ORDER BY `name`;
  32.  
  33. # 7. Find Towns Not Starting With
  34. SELECT * FROM `towns`
  35. WHERE `name` NOT LIKE ('r%') AND `name` NOT LIKE ('b%') AND `name` NOT LIKE ('d%')
  36. ORDER BY `name`;
  37.  
  38. # 8. Create View Employees Hired After
  39. CREATE VIEW v_employees_hired_after_2000 as
  40. SELECT `first_name`, `last_name` FROM `employees`
  41. WHERE year(hire_date) > 2000;
  42. SELECT * FROM v_employees_hired_after_2000;
  43.  
  44. # 9. Length of Last Name
  45. SELECT `first_name`, `last_name` FROM `employees`
  46. WHERE char_length(`last_name`) = 5;
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement