Advertisement
BossRA

mySQL questions

Dec 11th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. 1. Using the employees database, select all columns from employees who were hired in October of any year. Limit the results to 50 rows. ===>>> select * from employees where month(hire_date) = 10 limit 50;
  2.  
  3. 2. Using the employees database, select all columns from employees database. Show only those employees who were hired in even-numbered days. Limit results to 100.
  4. ===>>> Select * from employees where day(hire_date) %2 = 0 limit 100;
  5.  
  6. 3. (5 points) Display the last name and first name columns as one column labeled "Full Name" with the format "Last Name, First Name" and display the birth_date column labeled "Birth Date". Limit results to 50 rows.
  7. Output:
  8. Full Name Birth Date
  9. Facello, Georgi 1953-09-02
  10. Simmel, Bezalel 1964-06-02
  11. ===>>> select comcat(last_name, ", ", first_name) as "Full Name", birth_date as "Birth Date" from employees limit 50
  12.  
  13.  
  14. 4. (10 points) Display all columns from the dept_emp table and display rows for the Marketing department. Limit to 50 rows.
  15. Output:
  16. emp_no dept_no from_date to_date
  17. 11833 (intentionally left blank) 1999-07-15 9999-01-01
  18. 11841 (intentionally left blank) 1996-04-02 1996-10-24
  19. ===>>> select * from dept_emp where dept_no = 'd001' limit 50
  20.  
  21. 5. (10 points) Show all the salaries for employees during the years 1990, 1993, and 1996. Limit to 100 rows.
  22. Output:
  23. emp_no salary from_date to_date
  24. 10011 56753 '1996-01-21' '1996-11-09'
  25. 10033 60433 '1993-03-16' '1993-03-24'
  26. 10082 48935 '1990-01-03' '1990-01-15'
  27. ===>>> select * from salaries where year(from_date) in(1990, 1993, 1996) and year(to_date) in (1990, 1993, 1996) limit 100
  28.  
  29. 6. (5 points) Count the number of male employees who were born in the year 1956. Label the column as "1956 Babies"
  30. Output:
  31. 1956 Babies
  32. 13822
  33. ===>>> select count(emp_no) as "1956 Babies" from employees where gender = 'm' and year(birth_date) = 1956
  34.  
  35. 7. (10 points) For all employees with salaries less than 41,000. Display employee number labeled as "ID #", salary as "Salary" and add a column labeled "Bonus" where the value is 10% of the employee's salary. Limit to 100 rows.
  36. Output:
  37. ID # Salary Bonus
  38. 10003 40006 4000.6
  39. 10004 40054 4005.4
  40. 10006 40000 4000.0
  41. ===>>> select empno as "ID #", salary as "Salary", (salary * .1) as "Bonus" from salaries where salary < 41000 limit 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement