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
Ïà¹ØÎĵµ£º
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 ......
vs2005ÖÐÎÞ·¨Á¬½ÓSQLÎÊÌâ
×î½üÔÚÑо¿ASP.NET£¬ÔÚ°²×°VS2005ºÍSQLÉÏ£¬ÎÊÌâ¶à¶à°¡£¬¿¨ÁËÎҺܶàÌ죬×îºóÔÚ²éÔÄÒ»¶Ñ×ÊÁϺÍÖØ×°ÎÞÊý´Îϵͳ֮ºó£¬ÖÕÓÚÑо¿³öΪʲôÎÒ²»ÄÜÁ¬½ÓÊý¾Ý¿âµÄÎÊÌâÁË£¬½â¾ö·½·¨ÈçÏ£º
¡¡¡¡(1)¿ªÊ¼->³ÌÐò->Microsoft SQL Server 2005->SQL Server 2005ÍâΧӦÓÃÅäÖÃÆ÷,ÔÚ´ò¿ªµÄ½çÃæµ¥»÷"·þÎñµÄÁ¬ ......
Ò»£®Êý¾ÝÍêÕûÐÔ
¾ÍÊÇΪÁË·ÀÖ¹Êý¾Ý¿âÖдæÔÚ²»·ûºÏÓïÒå¹æ¶¨µÄÊý¾Ý£¬ºÍ·ÀÖ¹ÒòÊäÈëÊä³ö´íÎó¶øÔì³ÉµÄÎÞЧ²Ù×÷»òÕß´íÎóÐÅÏ¢¶øÌá³öµÄ£¬Öƶ¨µÄһЩ¶ÔÔª×é¡¢ÊôÐÔºÍÓòµÄһЩԼÊøºÍ¹æ¶¨¡£
½â¾ö°ì·¨ÓÉ£º¹æÔò£¬Ä¬ÈÏÖµ£¬Ô¼ÊøºÍ´¥·¢Æ÷µÈ¡£
¶þ£®Ô¼Êø
......
SQLµÄ»ù±¾¶ÔÏóÖ÷ÒªÓг£Á¿£¬±íʾ·û£¬·Ö¸ô·û£¬±£Áô¹Ø¼ü×Ö¡£
1¡¢³£Á¿
³£Á¿ÊÇÒ»¸ö°üº¬ÎÄ×ÖÓëÊý×Ö£¬Ê®Áù½øÖÆ»òÊý×Ö³£Á¿¡£Ò»¸ö×Ö·û´®³£Á¿°üº¬µ¥ÒýºÅ('')»òË«ÒýºÅ("")×Ö·û¼¯ÖеÄÒ»¸ö»ò¶à¸ö×Ö·û¡£
Èç¹ûÏëÔÚµ¥ÒýºÅ·Ö¸ôµÄ×Ö·û´®ÖÐÓõ½µ¥¶ÀµÄÒýºÅ£¬¿ÉÒÔÔÚÕâ¸ö×Ö·ûÖÐÓû§Á¬ÐøµÄµ¥ÒýºÅ£¨¼´ÓÃÁ ......