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
Ïà¹ØÎĵµ£º
MS SQL SERVER 2005È«ÎÄË÷Òýѧϰ±Ê¼ÇÒ»
ÏÈÁ˽âÒ»ÏÂÈ«ÎÄË÷ÒýÊÇÈçºÎ´´½¨ºÍʹÓõÄ
´´½¨È«ÎÄË÷Òý:
ÔÚMS SQL SERVER 2005Àï,È«ÎÄË÷ÒýÊÇÒ»¸öµ¥¶ÀµÄ·þÎñÏî,ĬÈÏÊÇÆô¶¯µÄ,µ«ÊÇûÓÐÔÊÐíÊý¾Ý¿âÆôÓÃÈ«ÎÄË÷Òý,Èç¹ûÒ ......
CareGroup Ò½ÁÆ×éÖ¯¸ºÔð±£»¤2TB µÄ²¡ÈËÐÅÏ¢ºÍÏà¹ØÊý¾ÝµÄÒþ˽¼°ÍêÕûÐÔ¡£¸Ã×é֯λÓÚ²¨Ê¿¶Ù£¬ÊÇBeth Israel Deaconess ҽѧÖÐÐÄ£¨¹þ·ðҽѧԺµÄ½ÌѧҽԺ£©ÒÔ¼°ÁíÍâÈý¼ÒµØÇøÒ½ÔºµÄĸ¹«Ë¾¡£CareGroup ²ÉÓÃMicrosoft® SQL Server™ 2005£¬½«ÆäÊý¾Ý´æ´¢ÓÚ30¸öʵÀýµÄ390¸öÊý¾Ý¿âÖС£¸Ã×é֯ϣÍû½«Êý¾Ý¿âÉý¼¶µ½SQL Server 200 ......
-->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)± ......
Ôʼ±í£º
name course score
-----------------------------------------
ÕÅÈý ÓïÎÄ 80
ÕÅÈý & ......
/********************************
¹¦ÄÜ£º»ñÈ¡±íµÄ¿Õ¼ä·Ö²¼Çé¿ö
**********************************/
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tablespaceinfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
create table tablespaceinfo   ......