Guest User

Untitled

a guest
Jun 23rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. Student
  2. |-------------------------|
  3. | StudentID | Student_Name|
  4. |-------------------------|
  5. | 1 | John |
  6. | 2 | Sally |
  7. | 3 | Stan |
  8. ---------------------------
  9.  
  10. Class
  11. ------------------------
  12. | ClassID | Class_Name|
  13. ------------------------
  14. | 1 | Math |
  15. | 2 | Physics |
  16. ------------------------
  17.  
  18. Student_Class
  19. -----------------------
  20. | StudentID | ClassID |
  21. -----------------------
  22.  
  23. INSERT INTO Student_Class (StudentID, ClassID) VALUES (1, 2);
  24.  
  25. INSERT INTO Student_Class (StudentID, ClassID) VALUES (2, 1);
  26. INSERT INTO Student_Class (StudentID, ClassID) VALUES (3, 1);
  27. INSERT INTO Student_Class (StudentID, ClassID) VALUES (3, 2);
  28.  
  29. SELECT Student.Student_Name,
  30. Class.Class_Name
  31. FROM Student,
  32. Class,
  33. Student_Class
  34. WHERE Student.StudentID = Student_Class.StudentID
  35. AND Class.ClassID = Student_Class.ClassID;
  36.  
  37. ------------------------------
  38. | Student_Name | Class_Name |
  39. ------------------------------
  40. | John | Physics |
  41. | Sally | Math |
  42. | Stan | Physics |
  43. | Stan | Math |
  44. ------------------------------
  45.  
  46. student { StudentID, StudentName ... }
  47. classes { ClassID, ClassName ... }
  48. student_classes { StudentID, ClassID }
  49.  
  50. student_classes { StudentID, Year, ClassID }
  51.  
  52. Student Table
  53. -------------
  54. id
  55. first_name
  56. last_name
  57. dob
  58.  
  59. Class Table
  60. -----------
  61. id
  62. class_name
  63. academic_year
  64.  
  65. Student_Class Table
  66. -------------------
  67. student_id
  68. class_id
  69. year_taken
  70.  
  71. SELECT
  72. s.last_name + ', ' + s.first_name AS student_name,
  73. c.class_name,
  74. sc.year_taken
  75. FROM
  76. student s
  77. INNER JOIN
  78. student_class sc
  79. ON
  80. s.id = sc.student_id
  81. INNER JOIN
  82. class c
  83. ON
  84. sc.class_id = class.id
  85. ORDER BY
  86. s.last_name, sc.year_taken
  87.  
  88. Student Table with the following columns
  89. StudentID
  90. StudentLastName
  91. StudentFirstName
  92. (and so forth for all the data to describe a student)
  93.  
  94. Student Table with the following columns
  95. StudentID
  96. StudentLastName
  97. StudentFirstName
  98. (and so forth for all the data to describe a student)
  99.  
  100. Course table with the following columns
  101. CourseId
  102. CourseName
  103.  
  104. StudentCourse Table with the following columns
  105. StudentId
  106. CourseID
  107. CourseDate
  108.  
  109. Select StudentID,StudentLastName,StudentFirstName, CourseName, CourseDate
  110. from Student
  111. join StudentCourse on student. studentid = StudentCourse.StudentID
  112. join Course on Course.courseID = StudentCourse.CourseID
Add Comment
Please, Sign In to add comment