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

SQLͳ¼Æ´óÈ«ÊÕ²Ø°æ ¸öÈËʹÓÃ

ÎÄÕÂÀ´Ô´£ºIT¹¤³Ì¼¼ÊõÍø£¬ È«ÎÄÁ´½Ó£ºhttp://www.systhinker.com/html/81/n-11481.html
1.¼ÆËãÿ¸öÈ˵Ä×ܳɼ¨²¢ÅÅÃû
select name,sum(score) as allscore from stuscore group by name order by allscore
2.¼ÆËãÿ¸öÈ˵Ä×ܳɼ¨²¢ÅÅÃû
select distinct t1.name,t1.stuid,t2.allscore from stuscore t1,( select stuid,sum(score) as allscore from stuscore group by stuid)t2where t1.stuid=t2.stuidorder by t2.allscore desc
3. ¼ÆËãÿ¸öÈ˵¥¿ÆµÄ×î¸ß³É¼¨
select t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(select stuid,max(score) as maxscore from stuscore group by stuid) t2where t1.stuid=t2.stuid and t1.score=t2.maxscore
4.¼ÆËãÿ¸öÈ˵Äƽ¾ù³É¼¨
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(score) as avgscore from stuscore group by stuid) t2where t1.stuid=t2.stuid
5.Áгö¸÷Ãſγ̳ɼ¨×îºÃµÄѧÉú
select t1.stuid,t1.name,t1.subject,t2.maxscore from stuscore t1,(select subject,max(score) as maxscore from stuscore group by subject) t2where t1.subject=t2.subject and t1.score=t2.maxscore
6.Áгö¸÷Ãſγ̳ɼ¨×îºÃµÄÁ½Î»Ñ§Éú
select distinct t1.* from stuscore t1 where t1.id in (select top 2 stuscore.id from stuscore where subject = t1.subject order by score desc) order by t1.subject
7.ѧºÅ     ÐÕÃû     ÓïÎÄ      Êýѧ      Ó¢Óï      ×Ü·Ö   ƽ¾ù·Ö
select stuid as ѧºÅ,name as ÐÕÃû,sum(case when subject='ÓïÎÄ' then score else 0 end) as ÓïÎÄ,sum(case when subject='Êýѧ' then score else 0 end) as Êýѧ,sum(case when subject='Ó¢Óï' then score else 0 end) as Ó¢Óï,sum(score) as ×Ü·Ö,(sum(score)/count(*)) as ƽ¾ù·Öfrom stuscoregroup by stuid,name order by ×Ü·Ödesc
8.Áгö¸÷Ãſγ̵Äƽ¾ù³É¼¨
select subject,avg(score) as avgscore from stuscoregroup by subject
9.ÁгöÊýѧ³É¼¨µÄÅÅÃû
declare @tmp table(pm int,name varchar(50),score int,stuid int)insert into @tmp select null,name,score,stuid from stuscore where subject='Êýѧ' order by sc


Ïà¹ØÎĵµ£º

PL/SQL Best Practice On BULK COLLECT

On BULK COLLECT
By Steven Feuerstein Oracle ACE
Best practices for knowing your LIMIT and kicking %NOTFOUND
I have started using BULK COLLECT whenever I need to fetch large volumes of data. This has caused me some trouble with my DBA, however. He is complaining that although my programs mig ......

SQL 2005Ô¶³Ì·ÃÎʵÄÉèÖÃ

SQL 2005Ô¶³Ì·ÃÎʵÄÉèÖÃ
2009-02-27 08:13
1¡¢Ê×ÏÈ´ò¿ªSQL Server ÍâΧӦÓÃÅäÖÃÆ÷£¬µã»÷“·þÎñºÍÁ¬½ÓµÄÍâΧӦÓÃÅäÖÃÆ÷”£¬Ñ¡ÔñÊý¾Ý¿â→Ô¶³Ì·þÎñ£¬µãÉϱ¾µØÁ¬½ÓºÍÔ¶³ÌÁ¬½Ó£¬ÔÙµãÉÏͬʱʹÓÃtcp/ipºÍnamed pipes
2¡¢´ò¿ªSQL Server Configuration Manager£¬SQL Server 2005ÍøÂçÅäÖ㬽«TCP/IPÆôÓÃÁË¡£
3¡¢Ò» ......

SQL ServerÖеÄT SQLµÄ»ù±¾¶ÔÏó


    SQLµÄ»ù±¾¶ÔÏóÖ÷ÒªÓг£Á¿£¬±íʾ·û£¬·Ö¸ô·û£¬±£Áô¹Ø¼ü×Ö¡£
 1¡¢³£Á¿
 ³£Á¿ÊÇÒ»¸ö°üº¬ÎÄ×ÖÓëÊý×Ö£¬Ê®Áù½øÖÆ»òÊý×Ö³£Á¿¡£Ò»¸ö×Ö·û´®³£Á¿°üº¬µ¥ÒýºÅ('')»òË«ÒýºÅ("")×Ö·û¼¯ÖеÄÒ»¸ö»ò¶à¸ö×Ö·û¡£
 Èç¹ûÏëÔÚµ¥ÒýºÅ·Ö¸ôµÄ×Ö·û´®ÖÐÓõ½µ¥¶ÀµÄÒýºÅ£¬¿ÉÒÔÔÚÕâ¸ö×Ö·ûÖÐÓû§Á¬ÐøµÄµ¥ÒýºÅ£¨¼´ÓÃÁ ......

Ò»´ÎÉñÆæµÄSQL ´íÎóµ÷ÊÔ¾­Àú

ÉÏÖܽӵ½Ò»¸öÆæ¹ÖµÄbug£¬Ò»¸öÔø¾­ÔËÐеúܺõĴ洢¹ý³ÌͻȻ²úÉúÁË´íÎóµÄ½á¹û¡£
¸ºÔðά»¤µÄÐÖµÜÃǺܸºÔðÈεĶԴíÎó½øÐÐÁ˸ú×Ù£¬²¢°Ñ´íÎó¶¨Î»Ò»¸öÈçϵÄÓï¾ä£º
SELECT *
into SomeTable
from A join B on A.id=B.id
         join C on A.id=C.id
ËûÃÇ·¢ÏÖ´ÓSomeTable×ö²éѯµÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ