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

50Ìõ³£ÓÃsqlÓï¾ä

Student(S#,Sname,Sage,Ssex) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“”¿Î³Ì±È“”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
  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¡¢²éѯƽ¾ù³É¼¨´óÓÚ·ÖµÄͬѧµÄѧºÅºÍƽ¾ù³É¼¨£»
    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¡¢²éѯѧ¹ý“”²¢ÇÒҲѧ¹ý±àºÅ“”¿Î³ÌµÄͬѧµÄѧºÅ¡¢ÐÕÃû£»
  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¡¢²éѯ¿Î³Ì±àºÅ“”µÄ³É¼¨±È¿Î³Ì±àºÅ“&rdqu


Ïà¹ØÎĵµ£º

SQLÖг£Óú¯ÊýµÄÕûÀí

¶ÔÓÚsqlÖеĺ¯Êý¿ÉνÊǶàµÄ²»Ê¤Ã¶¾Ù£¬±¾ÎÄ´Ó³£Óú¯ÊýµÄ½Ç¶È¶ÔÆ亯Êý½øÐÐ×ܽ᣺1¡¢ÈÕÆÚºÍʱ¼äº¯Êý2¡¢×Ö·û´®º¯Êý3¡¢ÏµÍ³º¯ÊýÁ÷³Ì¿ØÖÆÓï¾ä
1¡¢  ÈÕÆÚºÍʱ¼äº¯Êý
¶ÔÓÚÈÕÆÚº¯ÊýÎÒÃÇ¿ÉÒÔ·ÖΪ2СÀà½øÐзÖÎö´¦Àí£¬
A¡¢ ÈÕÆÚµÄÕûÌå´¦Àíº¯Êý£¬¾ßÌåµÄº¬ÒåºÍÓï·¨ÈçÏÂËùʾ£º
DATEADD(datepart,number,date)
µÚÒ»¸ö²ÎÊý˵Ã÷ÒªÌí ......

MS SQL SERVER 2005È«ÎÄË÷Òý


MS SQL SERVER 2005È«ÎÄË÷Òýѧϰ±Ê¼ÇÒ»
      ÏÈÁ˽âÒ»ÏÂÈ«ÎÄË÷ÒýÊÇÈçºÎ´´½¨ºÍʹÓõÄ
      ´´½¨È«ÎÄË÷Òý:
      ÔÚMS SQL SERVER 2005Àï,È«ÎÄË÷ÒýÊÇÒ»¸öµ¥¶ÀµÄ·þÎñÏî,ĬÈÏÊÇÆô¶¯µÄ,µ«ÊÇûÓÐÔÊÐíÊý¾Ý¿âÆôÓÃÈ«ÎÄË÷Òý,Èç¹ûÒ ......

SQL²éѯÓï¾ä¾«»ªÊ¹ÓüòÒª

Ò»¡¢ ¼òµ¥²éѯ
¡¡¡¡¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
¡¡¡¡ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
¡¡¡¡SELECT nickname,email
¡¡¡¡from testtable
¡¡¡¡WHERE name='ÕÅÈý'
......

¸ü¶à¼òµ¥¶øʵÓÃµÄ DB2 SQL Óï¾ä


----start
ÎÊÌ⣺²é¿´DB2 °æ±¾---SELECT * from SYSIBM.SYSVERSIONS
ÎÊÌ⣺²é¿´ÏµÍ³ÖÐÓÐÄÄЩ±íÒÔ¼°ÕâЩ±íµÄ¸ÅÒªÐÅÏ¢£ºSELECT * from SYSCAT.TABLES
ÎÊÌ⣺²é¿´Ä³¸ö±íÓÐÄÄЩÁÐÒÔ¼°ÕâЩÁеĸÅÒªÐÅÏ¢£ºSELECT * from SYSCAT.COLUMNS WHERE  TABNAME=<YOUR_TABLE_NAME>
---´ýÐøδÍê
---¸ü¶à²Î¼û£ºDB2 SQL ¾«Ò ......

SQLÅжÏ×Ö¶ÎÀàÐÍ

-->Title:Generating test data
-->Author:wufeng4552
-->Date :2009-09-25 09:56:07
if object_id('tb')is not null drop table tb
go
create table tb(ID int,name text)
insert tb select 1,'test'
go
--·½·¨1
select sql_variant_property(ID,'BaseType') from tb
--·½·¨2
select object_name(ID)± ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ