SQL Database Pen Questions

Source: Internet
Author: User
Tags ming

Known relational pattern:

S (sno,sname) student relationship. SNO for school number, SNAME for name

C (cno,cname,cteacher) course relationship. CNO as course number, CNAME as course name, Cteacher as Instructor

SC (sno,cno,scgrade) course selection relationship. Scgrade as a result

The following 5 processes are required:

1. Find out the names of all students who have not been enrolled in the "Li Ming" teacher course

Select SNAME from S
Where not EXISTS (
Select * from Sc,c
Where SC. Cno=c.cno
And Cname= ' Li Ming '
and SC. SNO=S.SNO)

2. Names of students with two or more (including two) failed courses and their average scores are listed

select s.sno,s.sname,avg_scgrade=avg (SC. Scgrade)
From s,sc, (
Select sno
from sc
where scgrade<60
Group by  sno
Having count (distinct cno) >=2
) a where s.sno=a.sno and sc. Sno=a.sno
Group by s.sno,s.sname

3.   List all students who have studied the "1" course and learned the "2" course in the name
Select s.sno,s.sname
From s, (
Select sc. SNO
From sc,c
Where sc. Cno=c.cno
And c.cname in (' 1 ', ' 2 ')
Group by sno
Having count (distinct  CNO) =2
) sc where s.sno=sc. SNO

4.   List "1" class scores than the "2" students who have high grades of the student's school number  

Select S.sno,s.sname
From S, (
Select SC1. SNO
From SC sc1,c c1,sc sc2,c C2
Where SC1. Cno=c1. CNO and c1.name= ' 1 '
and SC2. Cno=c2. CNO and C2.name= ' 2 '
and SC1. SCGRADE>SC2. Scgrade
) SC Where S.SNO=SC. SNO

5. List the scores of all students with "1" class scores higher than the "2" class and their "1" and "2" lessons
Select s.sno,s.sname,sc.[1 results],sc.[2 class score]
From S, (
Select SC1. The result of Sno,[1 class is]=SC1. The result of Scgrade,[2 class is]=SC2. Scgrade
From SC sc1,c c1,sc sc2,c C2
Where SC1. Cno=c1. CNO and c1.name= ' 1 '
and SC2. Cno=c2. CNO and C2.name= ' 2 '
and SC1. SCGRADE>SC2. Scgrade
) SC Where S.SNO=SC. SNO

SQL Database Pen Questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.