Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sql server¸ß¼¶²éѯ


1)  ͳ¼Æ¸÷¸öϵµÄѧÉúÐÅÏ¢
select count(Sname) ×ÜÈËÊý,Sdept from Student group by Sdept
2)  ²éѯÐŹÜϵѧÉúµÄ×î´óÄêÁäºÍ×îСÄêÁä
select MAX(Sage) ×î´óÄêÁä,MIN(Sage) ×îСÄêÁä from Student where
Sdept='ÐŹÜϵ'
3)  ²éѯÐŹÜϵ×î´óÄêÁäºÍ×îСÄêÁäµÄѧÉúµÄÐÕÃû
  select Sname from Student where Sdept = 'ÐŹÜϵ' and
(Sage in (select max(Sage)from Student )
or Sage in (select min(Sage)from Student where Sdept = 'ÐŹÜϵ')
4)  ͳ¼ÆÑ¡ÐÞc01¿Î³ÌµÄѧÉúµÄ×î¸ß·Ö£¬×îµÍ·Ö£¬×ܳɼ¨ºÍƽ¾ù·Ö
select MAX(Grade) ×î¸ß·Ö,MIN(Grade) ×îµÍ·Ö,SUM(Grade) ×ܳɼ¨,AVG(Grade) ƽ¾ù·Ö
from SC WHERE Cno='c01'
5)  ²éѯËùÓÐѧÉúµÄÑ¡¿ÎÐÅÏ¢£¬ÒªÇóÁгöѧÉúѧºÅ¡¢ÐÕÃû¡¢¿Î³ÌÃûºÍ³É¼¨
   select Student.Sno,Sname,Cname,Grade from Student,SC,Course
    where Student.Sno=SC.Sno and Course.Cno=SC.Cno
6)  ͳ¼ÆÿÃſγ̵ÄÑ¡ÐÞÈËÊý
select count(Sno),Cno from SC group by Cno
7)  ͳ¼Æÿ¸öѧÉúÑ¡Ð޵ĿγÌÃÅÊý¼°×ܳɼ¨
select Sno,count(Cno) Ñ¡Ð޿γÌÊý,SUM(Grade) ×ܳɼ¨ from SC group by Sno
8)  ²éѯÄÄЩ¿Î³ÌûÓÐÈËÑ¡ÐÞ£¬ÒªÇóÁгö¿Î³ÌÃû¡¢¿Î³ÌºÅ
select Cno,Cname from Course where Cno not in(select Cno from SC)
9)  ²éѯ¸÷¿Æƽ¾ù³É¼¨³¬¹ý80·ÖµÄѧÉúÐÕÃû
    select Sname,SC.Sno ,avg(Grade) ƽ¾ù³É¼¨
    from Student,SC
where Student.Sno=SC.Sno group by SC.Sno,Sname having avg(Grade)>80
10)²éѯѡÐÞÁËc03ºÅ¿Î³ÌµÄͬѧËùÔÚµÄϵ¼°¸ÃͬѧµÄÐÕÃû£¨ÓÃÁ½ÖÖ·½·¨ÊµÏÖ£©
select Student.Sname,Sdept from Student where
Sno in (select Sno from SC where Cno='c03')
 
select Student.Sname,Sdept from Student,SC where
Student.Sno =SC.Sno and Cno ='c03'
11)²éѯ¡°Êý¾Ý¿â»ù´¡¡±ÕâÃſεijɼ¨ÔÚ80·ÖÒÔÉϵÄѧÉúÐÕÃû
   Select Sname from Student,SC,Course
where SC.Sno=Student.Sno and SC.Cno=Course.Cno and
Course.Cname='Êý¾Ý¿âÔ­Àí'and Grade>80;
12)ͳ¼Æƽ¾ù³É¼¨´óÓÚ70·ÖµÄ¿Î³ÌÃû
select Cname,AVG(Grade)from SC,Course where SC.Cno=Course.Cno
GROUP by SC.Cno,Cname  having AVG(Grade)>70
 
13)ͳ¼Æƽ¾ù³É¼¨´óÓÚ70·Öµ


Ïà¹ØÎĵµ£º

SQL SUBSTRINGµÄÓ÷¨

SQL ÖÐµÄ substring º¯ÊýÊÇÓÃÀ´×¥³öÒ»¸öÀ¸Î»×ÊÁÏÖеÄÆäÖÐÒ»²¿·Ö¡£Õâ¸öº¯ÊýµÄÃû³ÆÔÚ²»Í¬µÄ×ÊÁÏ¿âÖв»ÍêÈ«Ò»Ñù£º
MySQL: SUBSTR(), SUBSTRING()
Oracle: SUBSTR()
SQL Server: SUBSTRING()
×î³£Óõ½µÄ·½Ê½ÈçÏ (ÔÚÕâÀïÎÒÃÇÓÃSUBSTR()ΪÀý)£º
SUBSTR(str,pos): ÓÉ<str>ÖУ¬Ñ¡³öËùÓдӵÚ<pos>λÖÿªÊ¼µÄ× ......

SQL CREATE VIEWµÄÓ÷¨

ÊÓ¹Û±í (Views) ¿ÉÒÔ±»µ±×÷ÊÇÐéÄâ±í¸ñ¡£Ëü¸ú±í¸ñµÄ²»Í¬ÊÇ£¬±í¸ñÖÐÓÐʵ¼Ê´¢´æ×ÊÁÏ£¬¶øÊÓ¹Û±íÊǽ¨Á¢ÔÚ±í¸ñÖ®ÉϵÄÒ»¸ö¼Ü¹¹£¬Ëü±¾Éí²¢²»Êµ¼Ê´¢´æ×ÊÁÏ¡£
½¨Á¢Ò»¸öÊÓ¹Û±íµÄÓï·¨ÈçÏ£º
CREATE VIEW "VIEW_NAME" AS "SQL Óï¾ä"
"SQL Óï¾ä" ¿ÉÒÔÊÇÈκÎÒ»¸öÎÒÃÇÔÚÕâ¸ö½Ì²ÄÖÐÓÐÌáµ½µÄ SQL¡£
À´¿´Ò»¸öÀý×Ó¡£¼ÙÉèÎÒÃÇÓÐÒÔϵıí¸ñ£ ......

SQL TRUNCATE TABLEµÄÓ÷¨

ÓÐʱºòÎÒÃÇ»áÐèÒªÇå³ýÒ»¸ö±í¸ñÖеÄËùÓÐ×ÊÁÏ¡£Òª´ïµ½Õ߸öÄ¿µÄ£¬Ò»ÖÖ·½Ê½ÊÇÎÒÃÇÔÚ SQL DROP ÄÇÒ»Ò³ ¿´µ½µÄ DROP TABLE Ö¸Áî¡£²»¹ýÕâÑùÕû¸ö±í¸ñ¾ÍÏûʧ£¬¶øÎÞ·¨ÔÙ±»ÓÃÁË¡£ÁíÒ»ÖÖ·½Ê½¾ÍÊÇÔËÓà TRUNCATE TABLE µÄÖ¸Áî¡£ÔÚÕâ¸öÖ¸Áî֮ϣ¬±í¸ñÖеÄ×ÊÁÏ»áÍêÈ«Ïûʧ£¬¿ÉÊDZí¸ñ±¾Éí»á¼ÌÐø´æÔÚ¡£ TRUNCATE TABLE µÄÓ﷨ΪÏ£º
TRUNCATE ......

JavaÁ¬½ÓSQL Server 2000

Êý¾Ý¿â²Ù×÷ÏÖÔÚÊÇÏîÄ¿¿ª·¢µÄ¸ù±¾£¬Ñ§Ï°JavaÊ×ÏÈÓ¦¸Ãѧ»áÔõôÑùÁ¬½ÓÊý¾Ý¿â£¬ÓÃJavaÁ¬½ÓÊý¾Ý¿â¿É²»ÏñÓÃDelphiÕâÀ๤¾ßÄÇÑùÉ輸¸öÊôÐÔ¾ÍOK£¬Ëµ¼òµ¥Ò²¼òµ¥£¬Ëµ¸´ÔÓ£¬ÆäʵҲͦ¸´Ôӵģ¬¶øÇÒºÜÂé·³£¬Èç¹ûÊdzõѧ£¬¸ù±¾²»Äܱ£Ö¤µÚÒ»´Î¾ÍÁ¬½Ó³É¹¦£¬ÏÂÃæÒÔSQL Server 2000ΪÀý£¬ËµËµJavaÁ¬½ÓÊý¾Ý¿âµÄ»ù±¾·½·¨£¬Ò²¼Ç¼һÏÂÐĵá£
1¡¢Ï ......

sqlÓï¾ä µÃµ½ sql server ±íÖÐÁеÄÀàÐͺÍ˵Ã÷

ͨ¹ýSqlÓï¾ä»ñµÃ ÁеÄÀàÐͺÍ˵Ã÷:
  µÃµ½µÄ±íÍ·£º±íÃû|ÁÐÃû|ÀàÐÍ|˵Ã÷
  1£ºÕë¶Ôsql server 2000£¬ÔÚsql2000ÖУ¬Ê¹Óãºsysobjects,syscolumnsºÍsysproperties±í
    SELECT o.name as table_name,c.name AS col_name,type_name(c.xtype) AS type_name,isnull(p.value,'') AS col_Pro ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ