MySQL written statement

Student test scores Table exam table student

    

 1. All student information inquiry

SELECT `name`,`code` FROM student;

2. Wang students, learning No. 5, the student added to the table

INSERT INTO student (`name`,`code`) VALUES("小王",6);

3 John Doe modify language performance score of 85

UPDATE exam SET score=90 WHERE `code`=(SELECT `code` FROM student WHERE `code`=2 )AND `subject`="语文";

4. check out all the students all subjects, displayed: name, student number, academic grades, and discipline to learn numbers and sorting, no results students should check

SELECT `name`,stu.`code`,`subject`,`score` 
FROM student stu
LEFT JOIN exam em
ON stu.`code`=em.`code`
ORDER BY `code`,`subject`

The average score of all subjects query, display discipline, average

SELECT `subject`,AVG(score) FROM exam GROUP BY `subject`;

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/book3/p/11934894.html