Home > database >  Mysql, the SQL has simple writing? Thank you, and online ~ ~ ~
Mysql, the SQL has simple writing? Thank you, and online ~ ~ ~

Time:10-20

Mysql's topic, there are two tables:
Student table
ID Name
Alex 1
2 Sam
3 Alex
4 Amy
5 Chris

Backlog list
Student_ID Sub_ID
1 math
1 PE
2 math
2 CS
3 PE
4 Chinese

To query the names have a class of students, in alphabetical order, showing the two ways are
A:
Alex1
Alex3
Amy
Sam
The second way:
Alex
Alex
Amy
Sam

What is a simple writing? Thank you, and online ~ ~ ~

CodePudding user response:

The select b.n ame from backlog a inner join Student b on a.S tudent_ID=b.i d order by b.n ame

CodePudding user response:

This not line, so the Sam will have two lines, the problem of the difficulty is that the normal students regardless of several class, just show a line of name, and two men named Alex, same name, student id is different, the two names are displayed

CodePudding user response:

What are the rules of the way in the kitchen,

CodePudding user response:

A table is students, is a student curriculum schedule table, to grasp what students have class now,
If there is no name repetition, is very simple, it is ok to distinct, now has the same name, the namesake, how to correctly grasp, or the name of the same name as required and then add a student id to distinguish, if not add student id can catch out the zhangs class students also ok

CodePudding user response:

 
The SELECT b.n ame FROM backlog a inner join
Student b on a.S tudent_ID=b.i d group by b.i d order by b.n ame.