7-28 learning database

7-28

 

select * from STUDENT;
select * from STU_COURSE;
select * from SCLASS;
select * from MAJOR;
select * from COURSE;

1. queries all participants name, age (integer display, such as display of 24-year-old 24.75 years old), the professional name of science, belongs to the class name  

select STU_NAME,         

CLASS_NAME,         

MAJOR_NAME,         

round(sysdate - s.stu_birthday) / 365    

 from STUDENT s, MAJOR m, SCLASS c     

where s.STU_MAJOR = m.major_id       

and s.stu_class = c.class_id;

2. Query the number of professional, professional name, the number of professional

 select MAJOR_ID,MAJOR_NAME,count(MAJOR)  

from MAJOR m,STUDENT s

 where m.MAJOR_ID=s.STU_MAJOR  

group by  MAJOR_ID,MAJOR_NAME;

3. Query member student number, student's name, its average score, and sorted in descending average

 select s.STU_ID, STU_NAME, avgSCORE    from STUDENT s,        

STU_COURSE c,      

  (select STU_ID, avg(SCORE) avgSCORE         

  from STU_COURSE        

  group by STU_ID) d   where s.STU_ID = c.STU_ID  

  and s.STU_ID = d.STU_ID   

order by avgSCORE desc;

4. queries on the 701 program, score higher than average test scores and student information

 select s.*, SCORE    

from STUDENT s, STU_COURSE c   

where s.STU_ID = c.STU_ID   

 and c.COURSE_ID = 701   

 and SCORE > (select avg(SCORE) from STU_COURSE);

5. Query cultivation has more than 6 credit points Student Information (selected seen as test scores not less than 60 repair credits)

select *
   from STUDENT s
  where exists (select 1
           from STUDENT a, COURSE c
          where s.stu_id = a.stu_id
            and a.stu_major = c.c_major having sum(c.c_score) > 6);

  6. Information inquiry failed in all subjects (test scores less than 60) of participants

 select *   

from STUDENT s, STU_COURSE c   

where s.stu_id = c.stu_id    

and SCORE < 60;

7. Query all subjects is higher than the average of 80 students of the school number, name, where the class name, average

 select s.STU_ID, STU_NAME, STU_CLASS, avg(t.score) 

   from STUDENT s, SCLASS c, STU_COURSE t  

where s.stu_class = c.class_id    

  and s.stu_id = t.stu_id having avg(t.score) > 80  

 group by s.STU_ID, STU_NAME, STU_CLASS;

8. query all subjects average higher than the average score of students lu students

 select s.STU_ID, STU_NAME, STU_BIRTHDAY, STU_ENTERDATE, STU_MAJOR, STU_CLASS    from STUDENT s, STU_COURSE t  

 where s.stu_id = t.stu_id

having   avg(score) > (select avg(score)                        

from STU_COURSE t, STUDENT s

                        where STU_NAME = 'Lu'

                         and s.stu_id = t.stu_id)

  group by s.STU_ID,

           STU_NAME,

           STU_BIRTHDAY,

           STU_ENTERDATE,

           STU_MAJOR,

           STU_CLASS;

9. query each class name, and the number of test scores (the class all students test scores are summed)

 select CLASS_NAME, count(1), sum(SCORE)

   from STU_COURSE t, SCLASS c, STUDENT s

  where s.stu_class = c.class_id

    and s.stu_id = t.stu_id

  group by CLASS_NAME;

10. Query class size is higher than the average class size for each class number, class name

 select CLASS_ID, CLASS_NAME

   from SCLASS c, STUDENT s

  where s.stu_class = c.class_id having

  count(stu_class) > (select avg(stu_class) from STUDENT)

  group by CLASS_ID, CLASS_NAME ;

Guess you like

Origin www.cnblogs.com/hole/p/11261008.html