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

SQL²éѯÿÐÐÖÐ×î´óÖµµÄ¼¼ÇÉ

--------------------------------------------------------------------------
--  Author : htl258(Tony)
--  Date   : 2010-04-23 08:08:36
--  Version:Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
--          Jul  9 2008 14:43:34
--          Copyright (c) 1988-2008 Microsoft Corporation
--          Developer Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
--  Blog   : http://blog.csdn.net/htl258
--  Subject: SQL²éѯÿÐÐÖÐ×î´óÖµµÄ¼¼ÇÉ
--------------------------------------------------------------------------
--> Éú³É²âÊÔÊý¾Ý±í:tb
 
IF NOT OBJECT_ID('[tb]') IS NULL
    DROP TABLE [tb]
GO
CREATE TABLE [tb](
a SMALLINT,
b SMALLINT,
c SMALLINT,
d SMALLINT,
e SMALLINT,
f SMALLINT,
g SMALLINT
)
INSERT [tb]
SELECT 1,2,3,4,5,2,3 UNION ALL
SELECT 4,5,6,7,7,2,0 UNION ALL
SELECT 4,9,6,7,7,9,6
GO
--SELECT * from [tb]
 
-->SQL²éѯÈçÏÂ:
 
SELECT *,
    (SELECT MAX(a)
     from(
       SELECT a UNION ALL
       SELECT b UNION ALL
       SELECT c UNION ALL
       SELECT d UNION ALL
       SELECT e UNION ALL
       SELECT f UNION ALL
       SELECT g
       ) AS t  
    ) AS maxvalue
from tb
 
 
/*
a      b      c      d      e      f      g      maxvalue
------ ------ ------ ------ ------ ------ ------ --------


Ïà¹ØÎĵµ£º

SQL ʹÓà CONVERT

ʹÓà CONVERT£º
CONVERT (data_type[(length)], expression [, style])
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),\'-\',\'\'),\' \',\'\'),\':\',\'\')
20040912110608
select CONVERT(varchar(12) , getdate(), 111 ) ......

sql ¸÷ÖÖ×Ö·û´®ºÏ²¢·½·¨ µÚ¶þÖÖ·½·¨ºÃ(ÀûÓú¯Êý)

--3.3.1 ʹÓÃÓα귨½øÐÐ×Ö·û´®ºÏ²¢´¦ÀíµÄʾÀý¡£
--´¦ÀíµÄÊý¾Ý
CREATE TABLE tb(col1 varchar(10),col2 int)
INSERT tb SELECT 'a',1
UNION ALL SELECT 'a',2
UNION ALL SELECT 'b',1
UNION ALL SELECT 'b',2
UNION ALL SELECT 'b',3
--ºÏ²¢´¦Àí
--¶¨Òå½á¹û¼¯±í±äÁ¿
DECLARE @t TABLE(col1 varchar(10),col2 varch ......

SQL ServerÑ¡ÔñÁ˷Ǿۼ¯Ë÷Òý¶ø²»ÊǾۼ¯Ë÷Òý

¾Û¼¯Ë÷Òý²»½ö°üº¬Ë÷ÒýµÄkeyÖµ£¬»¹°üº¬±íÊý¾Ý£»
·Ç¾Û¼¯Ë÷ÒýÖ»°üº¬Ë÷ÒýµÄkeyÖµ¡£
SQL ServerÔÚÓÐЩÇé¿öÏ£¬Óоۼ¯Ë÷ÒýºÍ·Ç¾Û¼¯Ë÷Òý´æÔÚʱ£¬»áÑ¡Ôñ×߷Ǿۼ¯Ë÷Òý£¬¶ø²»×ß¾Û¼¯Ë÷Òý¡£
Àý×ÓÈçÏ£º
ÔÚ SQL Server µÄadventureWorksÊý¾Ý¿âÏ£¬ÔËÐÐÈçÏÂÓï¾ä£º
select DepartmentID,Name from HumanResources.Department
Departm ......

sql ·þÎñÆ÷½ÇÉ« Êý¾Ý¿â½ÇÉ«



sql ·þÎñÆ÷½ÇÉ« Êý¾Ý¿â½ÇÉ«
·þÎñÆ÷½ÇÉ«
ËùÓеķþÎñÆ÷½ÇÉ«¶¼ÊÇ“¹Ì¶¨µÄ”½ÇÉ«£¬²¢ÇÒ£¬´ÓÒ»¿ªÊ¼¾Í´æÔÚÓÚÄÇÀï——×Ô°²×°ÍêSQL ServerµÄÄÇÒ»¿ÌÆð£¬Ä㽫ӵÓеÄËùÓзþÎñÆ÷½ÇÉ«¾ÍÒѾ­´æÔÚÁË¡£

½Ç¡¡¡¡É«
ÌØ¡¡¡¡ÐÔ

sysadmin
¸Ã½ÇÉ«Äܹ»Ö´ÐÐSQL ServerÉϵÄÈκβÙ× ......

³£ÓÃ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
  fr ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ