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

50¸ö³£ÓÃsqlÓï¾ä

Student(S#,Sname,Sage,Ssex) ѧÉú±í
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”¿Î³ÌµÍµÄËùÓÐͬѧµÄѧºÅ¡¢ÐÕÃû£»
  Select S#,Sname from (select Student.S#,Student.Snam


Ïà¹ØÎĵµ£º

º½¿Õ¹«Ë¾¹ÜÀíϵͳ(VC++ ÓëSQL 2005)

ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
      ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......

SQLÓïÑÔµÄCASEʹÓÃ×ܽá

 ×ª×Ôhttp://lavasoft.blog.51cto.com/62575/23373
SQLÓïÑÔµÄCASEÓï¾ä±¸Íü
 
¸ÅÊö£º
SQLÓï¾äÖеÄCASEÓï¾äÓë¸ß¼¶ÓïÑÔÖеÄswitchÓï¾ä£¬ÊDZê×¼SQLµÄÓï·¨£¬ÊÊÓÃÓëÒ»¸öÌõ¼þÅжÏÓжàÖÖÖµµÄÇé¿öÏ·ֱðÖ´Ðв»Í¬µÄ²Ù×÷¡£Áé»îÓ¦ÓÃCASEÓï¾ä¿ÉÒÔʹSQLÓï¾ä±äµÃ¼ò½àÒ׶Á£¬ÏÂÃæÔÚDB2»·¾³ÏÂͨ¹ýÒ»¸ö¼òµ¥µÄ²éѯÀ´Õ¹Ê¾SQL CASEÓ ......

MS SQLÊÓͼµÄ×÷ÓÃ

 µÚÒ»µã£º
ʹÓÃÊÓͼ£¬¿ÉÒÔ¶¨ÖÆÓû§Êý¾Ý£¬¾Û½¹Ìض¨µÄÊý¾Ý¡£
½âÊÍ£º
ÔÚʵ¼Ê¹ý³ÌÖУ¬¹«Ë¾Óв»Í¬½ÇÉ«µÄ¹¤×÷ÈËÔ±£¬ÎÒÃÇÒÔÏúÊÛ¹«Ë¾ÎªÀýµÄ»°£¬
²É¹ºÈËÔ±£¬¿ÉÒÔÐèҪһЩÓëÆäÓйصÄÊý¾Ý£¬¶øÓëËûÎ޹صÄÊý¾Ý£¬¶ÔËûû
ÓÐÈκÎÒâÒ壬ÎÒÃÇ¿ÉÒÔ¸ù¾ÝÕâһʵ¼ÊÇé¿ö£¬×¨ÃÅΪ²É¹ºÈËÔ±´´½¨Ò»¸öÊÓ
ͼ£¬ÒÔºóËûÔÚ²éѯÊý¾Ýʱ£¬Ö»Ðèse ......

SQLº¯ÊýSubstringÌáÈ¡²¿·Ö×Ö·û´®

¹¦ÄÜ£º·µ»Ø×Ö·û¡¢¶þ½øÖÆ¡¢Îı¾»òͼÏñ±í´ïʽµÄÒ»²¿·Ö
Óï·¨£ºSUBSTRING ( expression, start, length )
          SQL ÖÐµÄ substring º¯ÊýÊÇÓÃÀ´×¥³öÒ»¸öÀ¸Î»×ÊÁÏÖеÄÆäÖÐÒ»²¿·Ö¡£Õâ¸öº¯ÊýµÄÃû³ÆÔÚ²»Í¬µÄ×ÊÁÏ¿âÖв»ÍêÈ«Ò»Ñù£º
²ÎÊý£º
expression ×Ö·û´®¡¢¶þ½øÖÆ×Ö·û´®¡¢Î ......

¼Ç¼һЩsqlÓï¾äoracleµÄ

 select d.code,d.name, sum(w.weight) weight,round(avg(w.price),2) price,sum(w.money) money
from weight_info w left outer join t_dict d on w.productcode=d.code left outer  join t_balancecode b on w.balancecode=b.balancecode where 1=1 and w.operdate>TO_TIMESTAMP('2009-11-2 04:12:32.0', ' ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ