数据库原理及安全(四)

SELECT * from student
where Sage=(
SELECT Sage FROM student
WHERE Sname='李勇'
) AND Sname!='李勇'


SELECT Sno,Sname FROM student
WHERE Sno IN(
	SELECT Sno FROM sc
		WHERE Cno=(
			SELECT Cno FROM course
				WHERE Cname='数据库'
		)
)

SELECT Sno,Sname,Sage,Sdept
FROM student
WHERE Sage>(
SELECT Sage FROM student WHERE Sname='李勇'
)

SELECT Sno,Sname,Sage,Sdept
FROM student
WHERE Sage>(
SELECT AVG(Sage) FROM student WHERE Sdept='CS'
)

SELECT Sno,Sname,Sage,Sdept
FROM student
WHERE Sage>(
SELECT MAX(Sage) FROM student WHERE Sdept='CS'
) AND Sdept!='CS'

SELECT Sno,Cno FROM sc x
WHERE Grade>(
SELECT avg(Grade) FROM sc y WHERE x.Sno=y.Sno
)

SELECT Sno,Cno FROM sc x
WHERE Grade>(
SELECT avg(Grade) FROM sc y WHERE x.Cno=y.Cno
)

SELECT Sno,Sname,Sdept,Sage
FROM student x
WHERE Sage>(
SELECT AVG(Sage) FROM student y WHERE x.Sdept=y.Sdept
) 

#25
SELECT Sno, COUNT(*) AS Cnt, AVG(Grade) AS AveScore
FROM SC
GROUP BY Sno
HAVING min(Grade)>=60
ORDER BY AveScore DESC, Cnt DESC

SELECT Sno,Sname,Sdept
FROM student
WHERE Sage<(
SELECT min(Sage) FROM student WHERE Sdept='CS' 
) AND Sdept!='CS'

SELECT Sno,Grade FROM sc 
WHERE Grade>(
SELECT AVG(Grade) FROM sc WHERE Cno='1'
) AND Cno='1'

SELECT Sno,Sname,Sdept
FROM student x
WHERE Sage>(
SELECT AVG(Sage) FROM student y WHERE x.Sdept=y.Sdept
) 

#20
SELECT Sname FROM student
WHERE(
SELECT Sno NOT IN(
SELECT Sno FROM sc
WHERE Cno=(SELECT Cno FROM course WHERE Cname='数学')
)
)

你可能感兴趣的:(数据库,数据库,sql)