Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

sql - How can I put the students to their own class with their perspective class and teacher using MYSQL

So basically I'm studying mysql how can I put the student to their own class

Example 1810932 Al Jake ,his teacher would be Cris Greeg which the student will attend an english class 1810933 Alisson Zach ,his teacher would be Paul Jake which the student will attend to an mathematics and also Cris Greeg has a student named Al Jake and Paul Jake has a student named Alisson Zac

here is the code that I did but I cant get the exact result

select en.*
   ,sc.teacher
   ,sc.day
   ,sc.tstart
   ,sc.tend
   ,sc.descc
   ,sc.sem
   ,sc.room
   ,sc.school_year
from enrollment en 
inner join schedule sc 
    on sc.year = en.year

table : enrollment

table : schedule

EXPECTED OUTPUT


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you are missing one condition in join. Use following query:

select en.*
   ,sc.teacher
   ,sc.day
   ,sc.tstart
   ,sc.tend
   ,sc.descc
   ,sc.sem
   ,sc.room
   ,sc.school_year
from enrollment en 
inner join schedule sc 
    on sc.year = en.year
   And sc.section = en.section -- added this condition

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...