SQL SERVER²éѯÁ·Ï°Ï°Ìâ ÏÂÔØ±¾ÎÄ

ÄÚÈÝ·¢²¼¸üÐÂʱ¼ä : 2026/5/8 5:49:33ÐÇÆÚÒ» ÏÂÃæÊÇÎÄÕµÄÈ«²¿ÄÚÈÝÇëÈÏÕæÔĶÁ¡£

Éè½ÌѧÊý¾Ý¿âEducationÓÐÈý¸ö¹ØÏµ£º

ѧÉú¹ØÏµs£¨student_id£¬student_name£¬birthday£¬sex£¬major£©£» ѧϰ¹ØÏµsc£¨student_id£¬course_id£¬score£©£»

¿Î³Ì¹ØÏµcourse£¨course_id,course_name£¬term,period,credit£© ²éѯÎÊÌ⣺ µ¥±í²éѯ

1£º²éËùÓÐÄêÁäÔÚ20ËêÒÔϵÄѧÉúÐÕÃû¼°ÄêÁä¡£

select student_name,year(getdate()) - year(birthday) as ÄêÁä from s

where year(getdate()) - year(birthday) < 30 2£º²é¿¼ÊԳɼ¨Óв»¼°¸ñµÄѧÉúµÄѧºÅ select distinct student_id from sc

where score < 60

3£º²éËùÄêÁäÔÚ20ÖÁ23ËêÖ®¼äµÄѧÉúÐÕÃû¡¢Ïµ±ð¼°ÄêÁä¡£

select student_name,major,year(getdate()) - year(birthday) as ÄêÁä from s

where year(getdate()) - year(birthday) between 20 and 24 4£º²éÎ赸±àµ¼¡¢Ó¢ÓͨÐż¼ÊõרҵµÄѧÉúÐÕÃû¡¢ÐԱ𡣠select student_name, sex from s

where major in ('Î赸±àµ¼','Ó¢Óï','ͨÐż¼Êõ')

5£º²é²»ÊÇÎ赸±àµ¼¡¢Ó¢ÓͨÐż¼ÊõµÄѧÉúÐÕÃû¡¢ÐÔ±ð select student_name, sex from s

where major not in ('Î赸±àµ¼','Ó¢Óï','ͨÐż¼Êõ') 6£º²éËùÓÐÐÕ¡°Áõ¡±µÄѧÉúµÄÐÕÃû¡¢Ñ§ºÅºÍÐԱ𡣠select student_name,student_id,sex from s

where student_name like 'Áõ%'

8£º²éËùÓв»ÐÕ¡°ÕÅ¡±ÇÒµ¥ÃûµÄѧÉúµÄÐÕÃû¡£ select student_name from s

where student_name not like 'ÕÅ_' 9£º²éC++¿Î³ÌµÄ¿Î³ÌºÅ¡£ select course_id from course

where course_name='C++'

10£º²éȱ¿¼µÄѧÉúµÄѧºÅºÍ¿Î³ÌºÅ¡£ select student_id,course_id from sc

where score is null

11£º²é¿ª¿ÎѧÆÚΪ¿ÕÖµµÄ¿Î³Ì±àºÅºÍÃû³Æ¡£

select course_id,course_name from course

where term is null

12£º²éÐÅÏ¢¹ÜÀíרҵ20ËêÒÔϵÄѧÉúµÄѧºÅºÍÐÕÃû¡£ select student_id,student_name from s

where major='ÐÅÏ¢¹ÜÀí' and year(getdate()) - year(birthday)<20 13£º²éÎ赸±àµ¼×¨ÒµÐÔ±ðΪٵÄѧÉúÐÕÃû¡¢ÐԱ𡣠select student_name,sex from s

where major='Î赸±àµ¼' and sex='Å®'

14£º²éѯѡÐÞÁË110010¿Î³ÌµÄѧÉúµÄѧºÅºÍ³É¼¨£¬Æä½á¹û°´·ÖÊýµÄ½µÐòÅÅÁС£ select student_id,score from sc

where course_id='110010' order by score desc

15£º²éѯȫÌåѧÉúµÄÇé¿ö£¬²éѯ½á¹û°´ËùÔÚרҵÉýÐòÅÅÁУ¬¶ÔͬһϵÖеÄѧÉú°´ÄêÁä½µÐòÅÅÁС£ select * from s

order by major asc,year(getdate()) - year(birthday) desc 16£º²éѯѧÉú×ÜÈËÊý¡£ select count(*) as ÈËÊý from s

17£º²éѯѡÐÞÁ˿γ̵ÄѧÉúÈËÊý¡£ select count(*) as Ñ¡Ð޿γÌÈËÊý from sc

18£º¼ÆËãÑ¡ÐÞÁË110010¿Î³ÌµÄѧÉúƽ¾ù³É¼¨¡££¨¸ÄΪC++£© select avg(score) as ƽ¾ù³É¼¨ from sc

where course_id=

(select course_id from course

where course_name='C++' )

19£º²éѯѧϰ110010¿Î³ÌµÄѧÉú×î¸ß·ÖÊý¡£ select max(score) as ×î¸ß·Ö from sc

where course_id='110010'

20£º²éѯ¸÷¸ö¿Î³ÌºÅÓëÏàÓ¦µÄÑ¡¿ÎÈËÊý¡££¨¸ÄΪ¿Î³ÌÃû³Æ£© select course_name,count(*) as ÈËÊý from sc,course

where sc.course_id=course.course_id group by course_name

21£º²éѯÖÁÉÙÑ¡ÐÞÁ½Ãſγ̵ÄѧºÅ¡£ select student_id from sc

group by student_id having count(*) > 2

22£º²éѯѡÐ޿γ̳¬¹ý3ÃŵÄѧÉúÐÕÃû¼°¿Î³ÌÃÅÊý select student_name,count(*) as ¿Î³ÌÃÅÊý from s,sc

where s.student_id=sc.student_id group by student_name having count(*) > 3

¶à±í²éѯ

23£º²éѯÿ¸öѧÉú¼°ÆäÑ¡Ð޿γ̵ÄÇé¿ö¡£ select *

from s,sc,course

where s.student_id=sc.student_id and sc.course_id=course.course_id 24£º²éѯѡÐÞÁË110011¿Î³ÌÇҳɼ¨ÔÚ90·ÖÒÔÉϵÄѧÉúÐÅÏ¢¡£ select * from s,sc

where s.student_id=sc.student_id and course_id='110010' and score>90 25£º²éѯÿ¸öѧÉúµÄÐÕÃû£¬Ñ¡Ð޵ĿγÌÃû¼°Æä³É¼¨¡£ select student_name,course_name,score from s,sc,course

where s.student_id=sc.student_id and sc.course_id=course.course_id

×Ó²éѯ

27£º²éѯѡÐÞÁË110011¿Î³ÌµÄѧÉúÐÕÃû¡£ select student_name from s

where student_id in

(select student_id from sc

where course_id='110010' )

28£º²éѯÓë¡°ÁºæÃæÃ¡±ÔÚͬһ¸öרҵѧϰµÄѧÉúѧºÅ¡¢ÐÕÃûºÍרҵ¡£ select student_id,student_name,major from s

where major=

(select major from s

where student_name='ÁºæÃæÃ' )

29£º²éѯѡÐ޿γÌÃûΪ¡°C++¡±µÄѧÉúѧºÅºÍÐÕÃû¡£ select student_id,student_name from s

where student_id in

(select student_id from sc

where course_id= (select course_id from course

where course_name='C++' ) )

30£º²éѯÖÁÉÙÑ¡Ð޿γ̺ÅΪ110010ºÍ110011µÄÐÕÃû¡£

select student_name from s

where student_id in ( select s1.student_id from sc s1,sc s2

where s1.course_id='110010' and s2.course_id='110011' and s1.student_id=s2.student_id )

31£º²éѯѡÐÞ¡°C++¡±µÄ×î¸ß·ÖµÄѧÉúÐÕÃû£¬ÐÔ±ð£¬Ïµ±ð select student_name,sex,major from s,sc

where s.student_id = sc.student_id and course_id in

( select sc.course_id from sc,course

where sc.course_id = course.course_id and course_name = 'C++' )

and score =

( select max(score) from sc,course

where sc.course_id = course.course_id and course_name = 'C++' )

32£º²éѯËùÓÐδѡÐÞC++¿Î³ÌµÄѧÉúÐÕÃû¡£ select student_name from s

where not exists

(select * from sc

where course_id=

( select course_id from course

where course_name='C++') and sc.student_id=s.student_id )

1. £¨ A £©ÊÇλÓÚÓû§Óë²Ù×÷ϵͳ֮¼äµÄÒ»²ãÊý¾Ý¹ÜÀíÈí¼þ£¬ËüÊôÓÚϵͳ

Èí¼þ£¬ËüΪÓû§»òÓ¦ÓóÌÐòÌṩ·ÃÎÊÊý¾Ý¿âµÄ·½·¨¡£Êý¾Ý¿âÔÚ½¨Á¢¡¢Ê¹ÓúÍά»¤Ê±ÓÉÆäͳһ¹ÜÀí¡¢Í³Ò»¿ØÖÆ¡£ A£®DBMS B£®DB £¨database£© C£®DBS D£®DBA

2¡¢²éѯ±íÖеÄǰ3Ìõ¼Ç¼ʹÓõĹؼü×ÖÊÇ£¨ D £©

A¡¢up 3 B¡¢down 3 C¡¢pre 3 D¡¢top 3 3. SQL Server°²×°³ÌÐò´´½¨4¸öϵͳÊý¾Ý¿â£¬ÏÂÁÐÄĸö²»ÊÇ£¨ C £©ÏµÍ³

Êý¾Ý¿â¡£

A. Master B. Model C. pub D. msdb

4. ÏÂÁÐÄĸö²»ÊÇsql Êý¾Ý¿âÎļþµÄºó׺£¨À©Õ¹Ãû£©¡££¨ C £© A£®.mdf B£® .ldf C£®.tif D£®.ndf 5. SQLµÄÊÓͼÊÇ´Ó£¨ C £©Öе¼³öµÄ¡£

A. »ù±¾±í B. ÊÓͼ C. »ù±¾±í»òÊÓͼ D. Êý¾Ý¿â 6. ÔÚSQLÓïÑÔÖУ¬½¨Á¢´æ´¢¹ý³ÌµÄÃüÁîÊÇ( A ) A¡¢CREATE PROCEDURE B¡¢CREATE RULE C¡¢CREATE DURE D¡¢CREATE FILE 7. SQLÓïÑÔÖУ¬É¾³ý±íÖÐÊý¾ÝµÄÃüÁîÊÇ( A )¡£ A. DELETE B. DROP C. CLEAR D. REMOVE

8. ÔÚMS SQL ServerÖУ¬ÓÃÀ´ÏÔʾÊý¾Ý¿âÐÅÏ¢µÄϵͳ´æ´¢¹ý³ÌÊÇ( D )¡£ A. sp_dbhelp B. sp_db C. sp_help D. sp_helpdb

9. Microsoft ¹«Ë¾µÄSQL Server 2005 Êý¾Ý¿â¹ÜÀíϵͳһ°ãÖ»ÄÜÔËÐÐÔÚ

£¨ A £©¡£

A. Windows ƽ̨ B. UNIXƽ̨ C. LINXƽ̨ D. NetWare ƽ̨ 10. SQL Server 2005 µÄÎïÀí´æ´¢Ö÷Òª°üÀ¨3ÀàÎļþ£¨A £©¡£ A. Ö÷Êý¾ÝÎļþ¡¢´ÎÊý¾ÝÎļþ¡¢ÊÂÎñÈÕÖ¾Îļþ B. Ö÷Êý¾ÝÎļþ¡¢´ÎÊý¾ÝÎļþ¡¢Îı¾Îļþ C. ±íÎļþ¡¢Ë÷ÒýÎļþ¡¢´æ´¢Îļþ D. ±íÎļþ¡¢Ë÷ÒýÎļþ¡¢Í¼±íÎļþ 11. SQL Server 2000 ϵͳÖеÄËùÓÐϵͳ¼¶ÐÅÏ¢´æ´¢ÓÚÄĸöÊý¾Ý¿â£¨ A £©¡£ A. master B. model C. tempdb D.msdb 12¡¢ÏÂÁÐ˵·¨ÕýÈ·µÄÊÇ£¨ B £©¡£

A ¡¢ÊÓͼÊǹ۲ìÊý¾ÝµÄÒ»ÖÖ·½·¨£¬Ö»ÄÜ»ùÓÚ»ù±¾±í½¨Á¢¡£ B ¡¢ÊÓͼÊÇÐé±í£¬¹Û²ìµ½µÄÊý¾ÝÊÇʵ¼Ê»ù±¾±íÖеÄÊý¾Ý¡£ C ¡¢Ë÷Òý²éÕÒ·¨Ò»¶¨±È±íɨÃè·¨²éѯËٶȿ졣