SQL query Upgrade version

Source: Internet
Author: User
Tags ming

According to the existing student table, curriculum, select the course relationship form, query one. Students who have not had the class of teacher Li Ming, inquire
Second, the name of the student who has studied course a and studied B
SQL code
s table [sno,sname]--student table
c table [Cno,cname,cteather]--timetable
SC table [Sno,cno,scgrade]--Course selection Relationship Table

Inquiry one: The name of the student who did not take the class of teacher Li Ming
Select sname from S where NOT exists
(Select*from sc,c where sc.cno=c.cno and c.cteather= ' Li Ming ' and Sc.sno=s.sno)

Query two: List the names of students with two or more (including two) failed courses and their average scores
SELECT S.sno,s.sname,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


Query three: Students who have studied a course and have studied the B-class name
SELECT S.sno,s.sname
From S, (
SELECT SC. SNO
From Sc,c
WHERE SC. Cno=c.cno
and C.cname in (' A ', ' B ')
GROUP by SNO
) SC WHERE S.SNO=SC. SNO

Question Four
List all students with "1" Grade score higher than 2nd class
SELECT S.sno,s.sname
From S,SC SC1,SC SC2
WHERE SC1. cno= ' 1 '
and SC2. sno= ' 2 '
and SC1. Cno=s.cno
and SC1. SCGRADE>SC2. Scgrade

Question Five
List the number of students with "1" class scores higher than "2" and their "1" courses
And the results of the "2" course.
SELECT SC1. The result of Sno,[1 class is]=SC1. The result of Scgrade,[2 class is]=SC2. Scgrade
From SC SC1,SC SC2
WHERE SC1. cno= ' 1 '
and SC2. cno= ' 2 '
and SC1. SNO=SC2. SNO
and SC1. SCGRADE>SC2. Scgrade

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.