50Ìõ³£ÓÃsqlÓï¾ä
Student(S#,Sname,Sage,Ssex) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“”¿Î³Ì±È“”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
SELECT a.S# from (SELECT s#,score from SC WHERE C#='001') a,
(SELECT s#,score from SC WHERE C#='002') b
WHERE a.score>b.score AND a.s#=b.s#;
2¡¢²éѯƽ¾ù³É¼¨´óÓÚ·ÖµÄͬѧµÄѧºÅºÍƽ¾ù³É¼¨£»
SELECT S#,avg(score)
from sc
GROUP BY S# having avg(score) >60;
3¡¢²éѯËùÓÐͬѧµÄѧºÅ¡¢ÐÕÃû¡¢Ñ¡¿ÎÊý¡¢×ܳɼ¨£»
SELECT Student.S#,Student.Sname,count(SC.C#),sum(score)
from Student left Outer JOIN SC on Student.S#=SC.S#
GROUP BY Student.S#,Sname
4¡¢²éѯÐÕ“ÀÄÀÏʦµÄ¸öÊý£»
SELECT count(distinct(Tname))
from Teacher
WHERE Tname like 'Àî%';
5¡¢²éѯûѧ¹ý“Ҷƽ”ÀÏʦ¿ÎµÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
SELECT Student.S#,Student.Sname
from Student
WHERE S# not in (SELECT distinct( SC.S#) from SC,Course,Teacher WHERE SC.C#=Course.C# AND Teacher.T#=Course.T# AND Teacher.Tname='Ҷƽ');
6¡¢²éѯѧ¹ý“”²¢ÇÒҲѧ¹ý±àºÅ“”¿Î³ÌµÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
SELECT Student.S#,Student.Sname from Student,SC WHERE Student.S#=SC.S# AND SC.C#='001'and exists( SELECT * from SC as SC_2 WHERE SC_2.S#=SC.S# AND SC_2.C#='002');
7¡¢²éѯѧ¹ý“Ҷƽ”ÀÏʦËù½ÌµÄËùÓпεÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
SELECT S#,Sname
from Student
WHERE S# in (SELECT S# from SC ,Course ,Teacher WHERE SC.C#=Course.C# AND Teacher.T#=Course.T# AND Teacher.Tname='Ҷƽ' GROUP BY S# having count(SC.C#)=(SELECT count(C#) from Course,Teacher WHERE Teacher.T#=Course.T# AND Tname='Ҷƽ'));
8¡¢²éѯ¿Î³Ì±àºÅ“”µÄ³É¼¨±È¿Î³Ì±àºÅ“&rdqu
Ïà¹ØÎĵµ£º
¶ÔÓÚsqlÖеĺ¯Êý¿ÉνÊǶàµÄ²»Ê¤Ã¶¾Ù£¬±¾ÎÄ´Ó³£Óú¯ÊýµÄ½Ç¶È¶ÔÆ亯Êý½øÐÐ×ܽ᣺1¡¢ÈÕÆÚºÍʱ¼äº¯Êý2¡¢×Ö·û´®º¯Êý3¡¢ÏµÍ³º¯ÊýÁ÷³Ì¿ØÖÆÓï¾ä
1¡¢ ÈÕÆÚºÍʱ¼äº¯Êý
¶ÔÓÚÈÕÆÚº¯ÊýÎÒÃÇ¿ÉÒÔ·ÖΪ2СÀà½øÐзÖÎö´¦Àí£¬
A¡¢ ÈÕÆÚµÄÕûÌå´¦Àíº¯Êý£¬¾ßÌåµÄº¬ÒåºÍÓï·¨ÈçÏÂËùʾ£º
DATEADD(datepart,number,date)
µÚÒ»¸ö²ÎÊý˵Ã÷ÒªÌí ......
==============================================
µÚ1½²
ÔÚÏß¹Û¿´£º http://www.boobooke.com/v/bbk1389
ÊÓƵÏÂÔØ£º http://www.boobooke.com/v/bbk1389.zip
µÚ2½²
ÔÚÏß¹Û¿´£º http://www.boobooke.com/v/bbk1390
ÊÓƵÏÂÔØ£º http://www.boobooke.com/v/bbk1390.zip
µÚ3½²
ÔÚÏß¹Û¿´£º http ......
----start
ÎÊÌ⣺²é¿´DB2 °æ±¾---SELECT * from SYSIBM.SYSVERSIONS
ÎÊÌ⣺²é¿´ÏµÍ³ÖÐÓÐÄÄЩ±íÒÔ¼°ÕâЩ±íµÄ¸ÅÒªÐÅÏ¢£ºSELECT * from SYSCAT.TABLES
ÎÊÌ⣺²é¿´Ä³¸ö±íÓÐÄÄЩÁÐÒÔ¼°ÕâЩÁеĸÅÒªÐÅÏ¢£ºSELECT * from SYSCAT.COLUMNS WHERE TABNAME=<YOUR_TABLE_NAME>
---´ýÐøδÍê
---¸ü¶à²Î¼û£ºDB2 SQL ¾«Ò ......
ÔÎÄ£ºÁõÎä| ³£ÓõÄORACLE PL/SQL¹ÜÀíÃüÁîÒ»
ÊìϤORACLE¹ÜÀíµÄÒ»¶¨¶ÔÕâЩÃüÁî²»»áÄ°Éú£¬²»¹ý¶ÔÓÚÎÒÕâ¸ö¸Õ½Ó´¥ORACLE¹ÜÀíµÄÀ´Ëµ£¬»¹ÊÇÓбØÒª×öϼǼ£¬ÒÔ±ãËæʱ²é¿´¡£
Ò» µÇ¼SQLPLUS
sqlplus Óû§Ãû/ÃÜÂë@Êý¾Ý¿âʵÀý as µÇ¼½ÇÉ«;
Èç:Óû§sys(ÃÜÂëΪ123)ÒÔsysdbaµÄ½ÇÉ«µÇ¼Êý¾Ý¿âORACL£¬ÎÒÃÇ¿ÉÒÔÊäÈ룺sqlplus sy ......
--ÔÚÈÕ³£Î¬»¤£¬¿ª·¢Öг£Óöµ½Ð´Ò»ÏµÁнṹÀàÐ͵ÄsqlÓï¾ä£¬ºÜ·³ºÜÀÛÆäʵ¿ÉÒÔ
--ÀûÓÃSQL*PLUS»·¾³ÃüÁî Éú³É½Å±¾Îļþ
set heading off --¹Ø±ÕÁеıêÌâ
set feedback off --¹Ø±Õ·´À¡ÐÅÏ¢
  ......