SQLÓï¾äʹÓà һ¸öÌâÄ¿Éæ¼°µ½µÄ50¸öSqlÓï¾ä
×ªÔØ×Ô:http://www.diybl.com/course/7_databases/sql/sqlServer/2009124/154621_2.html
Ò»¸öÌâÄ¿Éæ¼°µ½µÄ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”µÄ³É¼¨±È¿Î³
Ïà¹ØÎĵµ£º
SQL¾ÛºÏº¯
±êÇ©£ºsql¾ÛºÏº¯Êý ÔÓ̸
¾ÛºÏº¯Êý£º
1.AVG ·µ»Ø×éÖÐµÄÆ½¾ùÖµ£¬¿ÕÖµ½«±»ºöÂÔ¡£
ÀýÈ磺use northwind // ²Ù×÷northwindÊý¾Ý¿â
Go
Select avg (unitprice) //´Ó±íÖÐÑ¡ÔñÇóunitpriceµÄƽ¾ùÖµ
& ......
ÎÒ¾³£ÎʵÄÒ»¸öÎÊÌâÊÇ£ºÄãÊÇÈçºÎÀ´À©Õ¹SQL DatabaseµÄ£¿ÓкܶàµÄ·½·¨¿ÉÒÔ×öµ½£¬±ÈÈçʹÓûº´æ£¬¹²Ïí»òÕßÓÃÆäËûµÄ¼¼Êõ½«Ñ¹Á¦´ÓÊý¾Ý¿âÊÍ·Å£¬µ«Êµ¼ÊÉÏÎÒÃÇûÓС£SQL Database´Ó¸ù±¾ÉÏÀ´ËµÊDz»¾ßÓÐÀ©Õ¹ÐԵģ¬ÎÒÃÇҲûÓÐħ·¨Ê¹ËüºöÈ»¾ßÓÐÀ©Õ¹ÐÔ¡£
ʲôÊÇÀ©Õ¹ÐÔ£¿
±ØÐë¾ßÓм¸Ï¼¸µã£º
ºáÏòÀ©Õ¹£º¸ü¶àµÄserver¿ÉÒÔ´øÀ´¸ü¸ßµÄÐÔÄÜ ......
SQL *PLUS RepostµÄ¿ª·¢·½·¨
ʹÓÃSQL*PLUS ¿ÉÖ±½ÓÔÚIE BrowserÖÐÉú³É¹æÕûµÄ×Ö·ûÐÍReport. ʵÏÖ·½·¨¼òµ¥£¬²¼ÊðÈÝÒס£
·½·¨:
1. ÀûÓÃÎı¾±à¼Æ÷±àдSQL*PLUS ½Å±¾£¬±£´æ³É .sql Îļþ¡£
2. ÉÏ´«sql ÎļþÖÁÓ¦ÓõÄsql Ŀ¼¡£
3.  ......
CREATE FUNCTION StringToBarcode
(@Value Varchar(50) )
RETURNS NVarchar(100)
AS
BEGIN
Declare @charCount int
Declare @charPos int, @minCharPos int
declare @currentChar int, @checksum int
Declare @isTableB int,@isValid int
&n ......
Ò»¸öʾÀýËÀËø
ÈÃÎÒÃÇ´ÓÕâÑùÒ»¸öʾÀý¿ªÊ¼ËµÆð£¬ËüÔÚ SQL Server 2000 ºÍ 2005 Öж¼ÄÜÒýÆðËÀËø¡£ÔÚ±¾ÎÄÖУ¬ÎÒʹÓà SQL Server 2005 µÄ×îРCTP£¨ÉçÇø¼¼ÊõÔ¤ÀÀ£¬Community Technology Preview£©°æ±¾£¬SQL Server 2005 Beta 2£¨7 Ô·¢²¼£©Ò²Í¬ÑùÊÊÓá£Èç¹ûÄúûÓÐ Beta 2 »ò×îÐ嵀 CTP °æ±¾£¬ÇëÏÂÔØ SQL Server 2005 Express µÄ ......