- create a table s, c, sc, s # is student id, name sn, sd, sa age; C # is the course number, cn course; G score The create table (s S # integer primary key, Sn varchar2 (10), Sd varchar2 (10), Sa integer );
The create table c ( C # integer primary key, Cn varchar2 (10) );
The create table sc ( S # integer, C # is an integer, G number (3, 1), Primary key (s #, c #) ); Insert into s values (23, 'zhangsan, tencent, 26). Insert into s values (24, 'lisi', 'ali, 26). Insert into s values (25, wangwu, tencent, 28). Insert into s values (26, "Bob", null, 29). Insert into c values (1, 'accounting'); Insert into c values (2, 'tax base); Insert into c values (3, 'statistics'); Insert into sc values (23,1,85.5); Insert into sc values (23,2,90); Insert into sc values (23,3,78); Insert into sc values (24,1,80); Insert into sc values (24,3,95); Insert into sc values (25,1,90); Insert into sc values (25,2,84); Insert into sc values (26,2,70); Insert into sc values (26,3,87);
- find out students of more than 2 student number and unit 1 -The select s.s #, s.s d from sc inner join s on sc. S # #=s.s Group by s.s #, s.s d having count (sc. C #) & gt; 2; 2 -The select s.s #, s.s d from s where s.s # in (select sc. S # from sc group by sc. S # having count (sc. C #) & gt; 2);
Although 2 spelled out the results of the same, there is a question I hope you help me answer the great god, according to the first writing, so that the grouping method have a wrong, wrong in where, trouble to explain in detail,
CodePudding user response:
Sorry, write wrong, basically be to see writing 1, where is the error
CodePudding user response:
Personal idea, when you are in a small amount of data's execution efficiency is better than 2, 1 but more data volume 2 is ok with 1
Two table 1 is set a table and then grouping, 2 is from the list number first, then combined with another,
When the small amount of data memory and CPU is enough, so fast
CodePudding user response:
Both writing is right,
It is more natural, understand the second
For execution plan First should walk a HASH JOIN, the second NESTED LOOP