selectstudent.*,course.*
from student join sc on student.sno=sc.sno join course on course.cno=sc.cno
wheresno in (select sno from sc group by sno having count(cno) >2) ÅÉÉú¹Øϵ(ûµ÷ÊÔ£¬¿ÉÒÔ²»½²)£º selectstudent.*,course.*
from student join sc on student.sno=sc.sno join course on course.cno=sc.cno
join (select sno from sc group by sno having count(cno) >3) as tt(sno) on tt.sno=student.sno 39(·½·¨¿ÉÒÔÓкܶàÖÖ)
select * from student where sno in (
selectsno from sc where grade=(
select max(grade) from sc where cno =(select cno from course where cname=¡¯Êý¾Ý¿âÔÀí¡¯
) and cno =(select cno from course where cname=¡¯Êý¾Ý¿âÔÀí¡¯)
) )
40select * from student where sno in ( selectsno from sc join (
select max(grade),cno from sc group by cno) as max_grade(m_grade,cno) onsc.cno=max_grade.cno and sc.grade=max_grade.m_grade ) 41
select * from student where sno in ( selectsno from sc group by sno having count(*) >=all (
select count(*) from sc group by sno
) ) 42 ÂÔ 43 ÂÔ
44 select top 3 with ties sname,sdept,grade from student join sc on Student.sno=sc.sno join course on course.cno=sc.cno where cname=¡¯VB¡¯ order by grade desc
45 select sname,sdept from student where sno not in (select sno from sc where cno=¡¯c01¡¯)
Select sname,sdept from student where not exists(select * from sc where sno=student.sno and cno=¡¯c01¡¯)
46 select Top 3 sname,sage,sdept from student order by sage desc 47 select cno,count(*) as total,avg(grade) as avggrade,max(grade) as maxgrade,min(grade)
as
mingrade
from
student
join
sc
on
student.sno=sc.sno where sdept=¡¯¼ÆËã»úϵ¡¯ group by cno
48 select c1.cname,c1.credit from course c1 join course c2 on c1.credit=c2.credit where c2.cname=¡¯Êý¾Ý½á¹¹¡¯
49 select c.cno,cname from course c left join sc on c.cno=sc.cno where sc.cno is null
50 select sname,sex from student where sno not in (
Select sno from sc join course on sc.cno=course.cno where cname=¡¯VB¡¯) And sdept=¡¯¼ÆËã»úϵ¡¯ Ï°Ì⣺ µ¥Ñ¡Ì⣺
B B A D A / C B A A D / B D D A B / C CC B B ¼òÊöÌ⣺
ÒÑÖªÓй˿͹ºÂòÉÌÆ·ÐÅÏ¢µÄÈýÕÅ±í£º¹Ë¿Í±íCustomer¡¢¶¨¹º±íOrder¡¢ÉÌÆ·±íCommodity¡£
°´ÒªÇó´´½¨ÈýÕÅ±í£º 1£® ±íÃû£ºCustomer
ÊôÐÔ£ºID ×Ö·ûÐÍ ×î´ó10¸ö×Ö·û ¡ª¡ª¹Ë¿Í±àºÅ NAME ×Ö·ûÐÍ ×î´ó16¸ö×Ö·û ¡ª¡ª¹Ë¿ÍÐÕÃû SEX ×Ö·ûÐÍ ×î´ó2¸ö×Ö·û ¡ª¡ªÐÔ±ð
MOBILE ×Ö·ûÐÍ ×î´ó11¸ö×Ö·û ¡ª¡ªÒƶ¯µç»° ADDRESS ×Ö·ûÐÍ ×î´ó50¸ö×Ö·û ¡ª¡ª¼Òͥסַ
Ô¼Êø£º ID¡ª¡ªÖ÷Â룻 NAME¡ª¡ª·Ç¿ÕÊôÐÔ£» SEX¡ª¡ªÈ¡Öµ¡°ÄС±»ò¡°Å®¡±£» MOBILE¡ª¡ªÎ¨Ò»ÐÔ£» ADDRESS¡ª¡ªÄ¬ÈÏΪUNKOWN£» ±íÃû£ºOrderBook
ÊôÐÔ£ºCSID ×Ö·ûÐÍ ×î´ó10¸ö×Ö·û ¡ª¡ª¹Ë¿Í±àºÅ CMID ×Ö·ûÐÍ ×î´ó12¸ö×Ö·û ¡ª¡ªÉÌÆ·±àºÅ COUNT ÕûÐÍ ¡ª¡ª¶¨¹ºÊýÁ¿ BOOKDATE ÈÕÆÚÐÍ ¡ª¡ª¶©»õÈÕÆÚ TAKEDATE ÈÕÆÚÐÍ ¡ª¡ª½»»õÈÕÆÚ
Ô¼Êø£ºCSID£¬CMID¡ª¡ªÖ÷Â룻 ¶¨¹ºÊýÁ¿Òª´óÓÚ0£» ¶©»õÈÕÆÚҪСÓÚ½»»õÈÕÆÚ£»
CSID¡ª¡ªÍâÂ룬ÒýÓÃCustomer±íµÄID£» CMID¡ª¡ªÍâÂ룬ÒýÓÃCommodity±íµÄID£» ±íÃû£ºCommodity
ÊôÐÔ£ºID ×Ö·ûÐÍ ×î´ó12¸ö×Ö·û ¡ª¡ªÉÌÆ·±àºÅ NAME ×Ö·ûÐÍ ×î´ó20¸ö×Ö·û ¡ª¡ªÉÌÆ·Ãû³Æ MANUFACTURE ×Ö·ûÐÍ ×î´ó20¸ö×Ö·û ¡ª¡ªÉú²ú³§ÉÌ
PRICE СÊýÐÍ ×î´ó²»³¬¹ý4λÊý£¬±£Áô2λСÊý ¡ª¡ªÉÌÆ·µ¥¼Û Ô¼Êø£ºID¡ª¡ªÖ÷Â룻 NAME¡ª¡ª·Ç¿Õ£» Õë¶ÔÉÏÃæµÄÈý¸ö»ù±¾±í×öÈçÏÂÁ·Ï°£º
2£®Íù»ù±¾±íCustomerÖвåÈë¹Ë¿ÍÔª×飨¡±0421F901¡±£¬¡±WU¡±£¬¡±Å®¡±£¬13980011001£©
3£®Íù»ù±¾±íCommodityÖвåÈëÒ»ÌõÉÌÆ·¼Ç¼£¨¡°03110408591¡±£¬¡°ÑÀ¸à¡±£¬¡°±£½à
¹«Ë¾¡±£¬5.00£©
4£®Ð޸ġ°WANGYAN¡±¹Ë¿Í¶¨¹ºÉÌÆ·µÄ¼Ç¼½»»õÈÕÆÚΪ2005-12-25¡£
Update order set taketime=¡¯2005-12-25¡¯ where csid in (select id from customer where name=¡¯wangyan¡¯) 5. ²éѯ¡°ANAN¡±¹Ë¿ÍµÄÊÖ»úºÅºÍסַ¡£
Select mobile, address from customer where name=¡¯anan¡¯ 6. ²éѯÉÌÆ·µÄƽ¾ù¼Û¸ñ¸ßÓÚ75ԪǮµÄ³§ÉÌÃû³Æ¡£
Select manufacture from commodity group by manufacture having avg(price) >75
7. ²éѯ¹Ë¿ÍµÄ¶¨¹ºÐÅÏ¢£¬²¢°´¶©»õÈÕÆÚÉýÐòÅÅÁУ¬Èô¶©»õÈÕÆÚÏàͬ£¬Ôò°´¶¨¹ºÊýÁ¿½µÐòÅÅÁС£
Select * from orderbook order by bookdate,countdesc 8. ²éѯ¶¨¹ºÊýÁ¿³¬¹ý100µÄ¹Ë¿ÍÐÕÃû¡¢µç»°ºÍסַ¡£
Select name, mobile, address from customer where id in(select csidfrom orderbook where count>100)
9. ²éѯûÓж©µ¥µÄÉÌÆ·±àºÅ¡¢Ãû³ÆºÍ³§ÉÌ¡£
Select id,name, manufacture from comodity where id not in(select csid from orderbook)
10. ²éѯ¶¨¹ºÁËÉÌÆ·ºÅΪ¡°M900532481¡±µÄ¹Ë¿Í×ÜÈËÊýºÍ×î¸ßÊýÁ¿¡£ Select count(*) ,max(count) from order where cmid=¡¯m900532481¡¯ 11. ²éѯ¶¨¹ºÁË¡°¿É±È¿Ë¡±ÉÌÆ·µÄ¹Ë¿Í±àºÅ¡¢ÐÕÃû¡£
Select id,name from customer where id in(select csid from order where cmid in(select id from comodity where name=¡¯ ¿É±È¿Ë¡¯))
12. ²éѯÉÌÆ·ÃûÖаüº¬¡°ÌÇ¡±µÄËùÓÐÉÌÆ·µÄ±àºÅ¡¢³§ÉÌ¡¢µ¥¼Û¡£
Select id,manufacture ,price from comodity where name like ¡®%ÌÇ%¡¯ 13. ²éѯÖÁÉÙÓÐÁ½Î»¹Ë¿Í¶¨¹ºµÄÉÌÆ·µÄÃû³Æ¡£
Select name from comodity where id in(select cmid from order group by cmid having count(*)>=2)
14. ²éѯ½ØÖÁ2005Äêµ×ËùÓÐÉÌÆ·¶©µ¥×îÍíµÄ½»»õÈÕÆÚ¡£
SELECT taketime from order where taketime = (select max(taketime) from order where taketime<¡¯2005-12-31¡¯) 15. ²éѯסַÖк¬ÓС°Èí¼þÔ°¡±Èý¸ö×ֵĹ˿ÍÈËÊý¡£
Select count(*) from customer where address like¡¯%Èí¼þÔ°%¡¯ 16£®²éѯ¶©¹ºÁË¡°±£½à¹«Ë¾¡±Éú²úµÄ²úÆ·Öм۸ñ×î¸ßµÄÉÌÆ·µÄ¿Í»§ÐÅÏ¢¡£ Select
customer.*
from
customer,OrderBook,Commodity
where
customer.id=orderbook.CSID and Commodity.id=orderbook.cmid and Commodity.id in
(Select id from Commodity where MANUFACTURE =¡°±£½à¹«Ë¾¡± and price=( Select max(price) from Commodity where MANUFACTURE =¡°±£½à¹«Ë¾¡±)) 17£®²éѯ2007Äê3Ô·ÝסַÔÚ¡°´óÁ¬¡±µÄ¹Ë¿Í¶Ô¡°ÉϺüѡ±ÉÌÆ·µÄ¶¨¹ºÐÅÏ¢£¬Áгö¹Ë¿ÍÐÕÃû£¬ÉÌÆ·ÊýÁ¿ºÍ¶¨¹ºÈÕÆÚ¡£
Select customer.name,count,BOOKDATE from customer,OrderBook,Commodity where
customer.id=orderbook.CSID and Commodity.id=orderbook.cmid and ADDRESS like ¡®%´óÁ¬%¡¯ and Commodity.name=¡¯ÉϺüѡ¯ and BOOKDATE between 2007-03-01 and 2007-03-31
18£®²éѯ¶©µ¥×î¶àµÄ¹Ë¿ÍÐÕÃû¡£
Select name from customer where id in(
Select CSID fromOrderBookgroup by csid having count(*)>=all(select Count(*) from orderbook group by csid))
19£®²éѯ¶¨¹ºÁË¡°±£½à¹«Ë¾¡±µÄÉÌÆ·×î¶àµÄ¿Í»§ÐÅÏ¢¡£ Select * from customer where id in(
Select csid from orderbook where cmid in(Select id from Commodity where
MANUFACTURE =¡°±£½à¹«Ë¾¡±) group by csid having count(*)>=all(select
count(*) from orderbook where cmid in(Select id from Commodity where
MANUFACTURE =¡°±£½à¹«Ë¾¡±) group by csid ))
20£®°Ñ¡°È¸³²ÄÌ·Û¡±µÄ¶¨¹ºÉÌÆ·¼Ç¼ȫ²¿É¾È¥¡£
Delete from order where cmid in (select id from commodity where name=¡¯È¸³²ÄÌ·Û¡¯)