[font=Impact]ÎÊÌâÃèÊö£º
ÒÑÖª¹Øϵģʽ£º
s (sno,sname£© ѧÉú¹Øϵ¡£
sno ΪѧºÅ£¬
sname ΪÐÕÃû
c (cno,cname,cteacher) ¿Î³Ì¹Øϵ¡£
cno Ϊ¿Î³ÌºÅ£¬
cname Ϊ¿Î³ÌÃû£¬
cteacher ΪÈονÌʦ
sc(sno,cno,scgrade) Ñ¡¿Î¹Øϵ¡£
scgrade Ϊ³É¼¨
ÒªÇóʵÏÖÈçÏÂ5¸ö´¦Àí£º
1£® ÕÒ³öûÓÐÑ¡ÐÞ¹ý¡°ÀîÃ÷¡±ÀÏʦ½²Êڿγ̵ÄËùÓÐѧÉúÐÕÃû
2£® ÁгöÓжþÃÅÒÔÉÏ£¨º¬Á½ÃÅ£©²»¼°¸ñ¿Î³ÌµÄѧÉúÐÕÃû¼°Æäƽ¾ù³É¼¨
3£® Áгö¼Èѧ¹ý¡°1¡±ºÅ¿Î³Ì£¬ÓÖѧ¹ý¡°2¡±ºÅ¿Î³ÌµÄËùÓÐѧÉúÐÕÃû
4£® Áгö¡°1¡±ºÅ¿Î³É¼¨±È¡°2¡±ºÅͬѧ¸ÃÃſγɼ¨¸ßµÄËùÓÐѧÉúµÄѧºÅ
5£® Áгö¡°1¡±ºÅ¿Î³É¼¨±È¡°2¡±ºÅ¿Î³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ¼°Æä¡°1¡±ºÅ¿ÎºÍ¡°2¡±ºÅ¿ÎµÄ³É¼¨
1. ÕÒ³öûÓÐÑ¡ÐÞ¹ý¡°ÀîÃ÷¡±ÀÏʦ½²Êڿγ̵ÄËùÓÐѧÉúÐÕÃû
--ʵÏÖ´úÂ룺
select sname from s
where not exists(
select * from sc,c
where sc.cno=c.cno
and c.cteacher='ÀîÃ÷'
and sc.sno=s.sno)
2. ÁгöÓжþÃÅÒÔÉÏ£¨º¬Á½ÃÅ£©²»¼°¸ñ¿Î³ÌµÄѧÉúÐÕÃû¼°Æäƽ¾ù³É¼¨
--ʵÏÖ´úÂ룺
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. Áгö¼Èѧ¹ý¡°1¡±ºÅ¿Î³Ì£¬ÓÖѧ¹ý¡°2¡±ºÅ¿Î³ÌµÄËùÓÐѧÉúÐÕÃû
--ʵÏÖ´úÂ룺
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. Áгö¡°1¡±ºÅ¿Î³É¼¨±È¡°2¡±ºÅͬѧ¸ÃÃſγɼ¨¸ßµÄËùÓÐѧÉúµÄѧºÅ
--ʵÏÖ´úÂ룺
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
5. Áгö¡°1¡±ºÅ¿Î³É¼¨±È¡°2¡±ºÅ¿Î³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ¼°Æä¡°1¡±ºÅ¿ÎºÍ¡°2¡±ºÅ¿ÎµÄ³É¼¨
--ʵÏÖ´úÂ룺
select sc1.sno,[1ºÅ¿Î³É¼¨]=sc1.scgrade,[2ºÅ¿Î³É¼¨]=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[/font]
wangchengming12 ÓÚ 2010-04-25 10:56:51·¢±í:
¶¥Ï£¡
wangchengming12 ÓÚ 2010-04-25 10:56:43·¢±í:
¶¥Ï£¡
wxy9288 ÓÚ 2009-11-04 13:30:33·¢±í:
Ö§³ÖÏÂ?~ Ï£Íû´ó¼Ò¶à¶àÌÖÂÛSQLserver
gxylcqx ÓÚ 2009-05-08 21:51:36·¢±í:
ºÃÏñÂÛ̳Êý¾Ý¿âÕâ¿éºÜÀä°¡,
¸øÂ¥Ö÷¶¥Ò»¸ö
NOBLE025 ÓÚ 2009-05-06 01:36:09·¢±í:
{:3_119:}