mysql Study Notes 3.5

Then notes training 3

For me the introduction a more difficult difficulty ! ! ! !

select * from sc;

 

 

 

 

the SELECT student.sno, sname, AVG (Grade) AS average
 from Student, sc
 the WHERE student.sno = sc.sno
 Group  by student.sno
 the HAVING  AVG (Grade) > 90 / * This is a condition I actually forgot to write qwq * / 
the Order  by Grade desc ;

 

 

 

 

 

 

 

 

 

 

 

 

I just forgot to write when the average score higher than 90 points this condition a ! ! ! ! ! ! ! ! ! ! !

 

After grouping there is a having to filter it! ! ! ! ! !

 

 

having clause and where there are similarities but also differences, all statements setting conditions.

 

having a screening group and where is screening record.

 

 

 

 

go on----------->

 

 

select student.sno, sname, avg (grade) as Average
from student,sc
where student.sno=sc.sno
group by student.sno
having avg (grade)> 90 / * This is a condition I actually forgot to write qwq * /
order by grade desc
limit 2;

 

 

 

 

 

 

 

 

 

2. Next start connecting from outside connections, fully connected like it, study and understand the master side of the SQL language of relational algebra language Oh, 2333!

 

 

 

Since the connection :

 

 

 

 

 

select * from student;

 

 

/ * Query the name and cloudy in the same Academy classmates * /
select s2.sname
from student as s1,student as s2
where s1.sname = 'cloudy'
and s1.sdeptno=s2.sdeptno;

  

 

 

 

Indirect queries each course Prerequisite

SELECT c1.cno, c1.cname, c2.cpre AS cppre
 from C AS C1, C AS C2 
 WHERE c1.cpre = c2.cno; / * find each course indirect Elective * /

 

 

Says a relevant, da da oh:

 

Such a table may be provided an outer code

The curriculum is the outer code Prerequisite curriculum! ! ! ! ! ! !

 

 

 

 

 

 

https://www.cnblogs.com/xiohao/archive/2013/06/28/3160265.html

 

ALTER  Table c
 the Add  constraint FK_c 
 Foreign  Key (cpre)
 References c (CNO); / * the curriculum field is set to c, c cpre outer code, a reference relationship is c * /

 

 

 

 

The next question -------- "

 

 

Code and the results are as follows:

 

 

SELECT c1.cno, c1.cname, c2.cpre AS cppre
 from C AS C1, C AS C2 
 WHERE c1.cpre = c2.cno; / * find each course indirect Elective * /

 

 

 

 

 

 

 

 

 

 

 

 

 

/ * Left outer join * / 
/ * query the case for all students ... * / 
the SELECT sname, CNO, Grade
 from Student left  the Join sc ON student.sno = sc.sno;

 

 

 

 

Right outer join

/ * Query all course information, ... * / 
the SELECT CNAME, sc.sno, Grade
 from sc right  Outer  the Join c ON sc.cno = c.cno; / * the right connection * /

 

Guess you like

Origin www.cnblogs.com/dragondragon/p/12455612.html