SQL³£ÓÃ實Àý£¨轉£©
50¸öSqlÓï¾ä£¬½ö¹©Ñ§Ï°£¡
Student(S#,Sname,Sage,S***) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
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¡¢²éѯƽ¾ù³É¼¨´óÓÚ60·ÖµÄͬѧµÄѧºÅºÍƽ¾ù³É¼¨£»
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¡¢²éѯѧ¹ý“001”²¢ÇÒҲѧ¹ý±àºÅ“002”¿Î³ÌµÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
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¡¢²éѯ¿Î³Ì±àºÅ“002”µÄ³É¼¨±È¿Î³Ì±àºÅ“001”¿
Ïà¹ØÎĵµ£º
ÔÚÊý¾Ý¿âÖУ¬ÓαêÊÇÒ»¸öÊ®·ÖÖØÒªµÄ¸ÅÄî¡£ÓαêÌṩÁËÒ»ÖÖ¶Ô´Ó±íÖмìË÷³öµÄÊý¾Ý½øÐвÙ×÷µÄÁé»îÊֶΣ¬¾Í±¾ÖʶøÑÔ£¬Óαêʵ¼ÊÉÏÊÇÒ»ÖÖÄÜ´Ó°üÀ¨¶àÌõÊý¾Ý¼Ç¼µÄ½á¹û¼¯ÖÐÿ´ÎÌáȡһÌõ¼Ç¼µÄ»úÖÆ¡£Óαê×ÜÊÇÓëÒ»ÌõT_SQL Ñ¡ÔñÓï¾äÏà¹ØÁª£¬ÒòΪÓαêÓɽá¹û¼¯£¨¿ÉÒÔÊÇÁãÌõ¡¢Ò»Ìõ»òÓÉÏà¹ØµÄÑ¡ÔñÓï¾ä¼ìË÷³öµÄ¶àÌõ¼Ç¼£©ºÍ½á¹û¼¯ÖÐÖ¸ ......
1.¼à¿Øµ±Ç°Êý¾Ý¿âËÔÚÔËÐÐʲôSQLÓï¾ä
SELECT osuser, username, sql_text from v$session a, v$sqltext b
where a.sql_address =b.address order by address, piece;
2.·ÖÎö±í
analyze table tablename compute statistics for all indexes;
analyze table tablename compute statistics for all indexed col ......
×îÏÈÏ£ÍûʹÓÃdatatable.columnsÖÖËùº¬ÓеÄÊôÐÔÖ±½Ó»ñÈ¡Ïà¹ØÐÅÏ¢£¬¿É²âÊÔºó·¢ÏÖ£¬³ýÁË×Ö¶ÎÃûºÍ×Ö¶ÎÀàÐÍ£¬ÆäËûÊý¾ÝÒ»¸ÅÕÒ²»µ½¡£
GOOGLEÍøÉϺܶàÖÖ·½·¨£¬ÆäÖÐ×îÖ±½ÓµÄÊÇÖ±½Ó²éѯSQLSERVERµÄinformation_schema.columsÊÓͼ£¬´ÓÖÐÖ±½Ó»ñÈ¡ÐÅÏ¢£¬²»¹ýºóÀ´ÓÖ·¢ÏÖ£¬ËäÈ»Êý¾ÝʱȫÁË£¬¿ÉÊÇÐèҪͨ¹ýºÜ¸´Ôӵķ½·¨£¨sys.all_columns sys ......
¾µäSQLÓï¾ä´óÈ«
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
¡¡¡¡SQL·ÖÀࣺ
¡¡¡¡DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡ ......