Advertisement
Mary_99

SQL LAB # COMPLETE TASKS

Oct 16th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 3.32 KB | None | 0 0
  1.  
  2. --1. get full details of tutors
  3. --SELECT * FROM tutors
  4.  
  5. --2. Get the names and last names of all students residing in lodz
  6. --SELECT name, last_name, city
  7. --FROM students
  8. --WHERE city  = 'Lodz'
  9.  
  10. --3.get the last name of all students with zip_code number = 12345
  11. --SELECT  last_name, zip_code
  12. --FROM students
  13. --WHERE zip_code = 12345
  14.  
  15. --4.Get subjects names with an id number less than 2 and greater than 5. Use
  16. --SELECT subject_name , subject_id
  17. --FROM subjects
  18. --WHERE  subject_id <2 OR subject_id  >5
  19.  
  20.  -- 5.Get the students numbers for all students that were born in Elsene or Los Angeles  (or both).
  21. --SELECT name , birth_place
  22. --FROM students
  23. --WHERE  birth_place IN ( 'Elsene' ,'Los Angeles')
  24.  
  25. -- 6.Get the students numbers for all students that were born in Lodz and residing in
  26. --Lodz or were born earlier than 1950. Use comparison operators.
  27.  --SELECT student_id, name , birth_place, birth_date ,city
  28. --FROM students
  29. --WHERE ( birth_place IN ( 'lodz') AND city IN('lodz')) OR DATEPART (YEAR, birth_date ) < 1950
  30.  
  31.  --7.Get names of the birth_places for all students.
  32.  --SELECT student_id, name , birth_place
  33. --FROM students
  34.  
  35. --8. Get students numbers and names of all students who do not live in Lodz.
  36.  --SELECT student_id, name ,city
  37. --FROM students
  38. --WHERE city NOT IN ( 'lodz')
  39.  
  40. --9.Get all the columns for every student whose zip_code number equals 12345, 22345 or 32445
  41. --SELECT student_id, name ,zip_code
  42. --FROM students
  43. --WHERE zip_code IN ( 12345, 223445, 32445)
  44.  
  45. --10.Get all the columns for every student whose zip_code number not equals 12345, 22345 or 32445
  46. --SELECT student_id, name ,zip_code
  47. --FROM students
  48. --WHERE zip_code NOT IN (12345, 223445, 32445)
  49.  
  50. -- 11.Get students numbers for all students that were born earlier than 1950 and later than 1940. Use the BETWEEN operator.
  51.  --SELECT student_id, name ,birth_date
  52. --FROM students
  53. --WHERE DATEPART (YEAR, birth_date ) BETWEEN 1940 AND 1950
  54.  
  55. -- 12.Get students numbers for all students that were born earlier than 1950 and later than 1940. Use the BETWEEN operator.
  56. --SELECT student_id, name ,birth_date
  57. --FROM students
  58. --WHERE DATEPART (YEAR, birth_date ) NOT BETWEEN 1940 AND 1950
  59.  
  60. --13. Get students numbers for all students residing in Lodz and which fax column is null.
  61. --SELECT student_id, name , city , fax
  62. --FROM students
  63. --WHERE ( city  IN ( 'lodz')) OR fax IS  NULL
  64.  
  65. --14. Get students numbers for all students whose registration_date column is not null
  66. --SELECT student_id, name ,registration_date
  67. --FROM students
  68. --WHERE registration_date IS NOT NULL
  69.  
  70. --15.Get the first and last names and numbers of all students whose first name contains the letter 'a' as the second character.
  71.  --SELECT  student_id, name, last_name
  72. --FROM students
  73. --WHERE name LIKE '_a%'
  74.  
  75. --16.Get full details of all students whose name begins with a character in the range C through W
  76.  --SELECT * FROM students
  77. --WHERE name LIKE '[c-w]%'
  78.  
  79. -- 17.Get full details of all students whose last name does not begin with the letter J, K,L, M, N, or O
  80. --and whose first name does not begin with the letter E or Z
  81.  --SELECT * FROM students
  82. --WHERE last_name NOT  LIKE '[JKLMNO]%' AND name  NOT  LIKE '[EZ]%'
  83.  
  84. --18.Get full details of all students whose name does not end with the 'n' character.
  85.  --SELECT * FROM students
  86. --WHERE name NOT  LIKE '%n'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement