42. Talaba ↔ kurs (ko'pga-ko'p bog'lanish)
O'rtachaTalaba va kurs ko'pga-ko'p bog'langan: bir talaba bir nechta kursga yozilishi,
bir kursda bir nechta talaba bo'lishi mumkin. Bog'lovchi jadval — enrollments.
Har bir yozilishni qaytaring: student, course.
Saralash: student alifbo, keyin course alifbo.
students: id, name · courses: id, title
enrollments: student_id, course_id
Jadval: students
| Ustun | Turi |
|---|---|
| id | INT PK |
| name | VARCHAR(60) |
Jadval: courses
| Ustun | Turi |
|---|---|
| id | INT PK |
| title | VARCHAR(60) |
Jadval: enrollments
| Ustun | Turi |
|---|---|
| student_id | INT |
| course_id | INT |
| PRIMARY | KEY(STUDENT_ID,COURSE_ID) |
Namuna ma'lumotlar
sample
students
| idINT | nameVARCHAR(60) |
|---|---|
| 1 | Aziz |
| 2 | Nilufar |
courses
| idINT | titleVARCHAR(60) |
|---|---|
| 1 | SQL |
| 2 | Python |
enrollments
| student_idINT | course_idINT |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
Kutilgan natija
| course | student |
|---|---|
| Python | Aziz |
| SQL | Aziz |
| SQL | Nilufar |
sample-full
students
| idINT | nameVARCHAR(60) |
|---|---|
| 1 | Aziz Karimov |
| 2 | Nilufar Rahimova |
| 3 | Bekzod Tursunov |
| 4 | Malika Yusupova |
| 5 | Sardor Nazarov |
courses
| idINT | titleVARCHAR(60) |
|---|---|
| 1 | SQL asoslari |
| 2 | Python |
| 3 | Algoritmlar |
| 4 | Statistika |
| 5 | Mashina o'rganish |
enrollments
| student_idINT | course_idINT |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 4 |
| 3 | 2 |
| 3 | 3 |
| 3 | 4 |
| 5 | 1 |
| 5 | 2 |
| 5 | 3 |
| 5 | 4 |
Kutilgan natija
| course | student |
|---|---|
| Algoritmlar | Aziz Karimov |
| Python | Aziz Karimov |
| SQL asoslari | Aziz Karimov |
| Algoritmlar | Bekzod Tursunov |
| Python | Bekzod Tursunov |
| Statistika | Bekzod Tursunov |
| SQL asoslari | Nilufar Rahimova |
| Statistika | Nilufar Rahimova |
| Algoritmlar | Sardor Nazarov |
| Python | Sardor Nazarov |
| SQL asoslari | Sardor Nazarov |
| Statistika | Sardor Nazarov |
sample-extra
students
| idINT | nameVARCHAR(60) |
|---|---|
| 2 | Malika Yusupova |
| 1 | Aziz Karimov |
courses
| idINT | titleVARCHAR(60) |
|---|---|
| 2 | Python |
| 1 | Mashina o'rganish |
enrollments
| student_idINT | course_idINT |
|---|---|
| 1 | 2 |
Kutilgan natija
| course | student |
|---|---|
| Python | Aziz Karimov |
O'xshash masalalar
Konsol
Natijani ko'rish uchun so'rovni ishga tushiring.
