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

SQL SERVERÄÚÖú¯Êý


¾ÛºÏº¯ÊýÈôÒª»ã×ÜÒ»¶¨·¶Î§µÄÊýÖµ£¬ÇëʹÓÃÒÔϺ¯Êý£º
SUM
·µ»Ø±í´ïʽÖÐËùÓÐÖµµÄ×ܺ͡£
Óï·¨
SUM(aggregate)
SUM Ö»ÄÜÓë°üº¬ÊýÖµµÄ×Ö¶ÎÒ»ÆðʹÓ᣽«ºöÂÔ¿ÕÖµ¡£
AVERAGE
·µ»Ø±í´ïʽÖÐËùÓзǿÕÖµµÄƽ¾ùÖµ£¨ËãÊõƽ¾ùÖµ£©¡£
Óï·¨
AVERAGE(aggregate)
AVERAGE Ö»ÄÜÓë°üº¬ÊýÖµµÄ×Ö¶ÎÒ»ÆðʹÓ᣽«ºöÂÔ¿ÕÖµ¡£
MAX
·µ»Ø±í´ïʽÖеÄ×î´óÖµ¡£
Óï·¨
MAX(aggregate)
¶ÔÓÚ×Ö·ûÁУ¬MAX 
½«°´ÅÅÐò˳ÐòÀ´²éÕÒ×î´óÖµ¡£½«ºöÂÔ¿ÕÖµ¡£
MIN
·µ»Ø±í´ïʽÖеÄ×îСֵ¡£
Óï·¨
MIN(aggregate)
¶ÔÓÚ×Ö·ûÁУ¬MIN 
½«°´ÅÅÐò˳ÐòÀ´²éÕÒ×îСֵ¡£½«ºöÂÔ¿ÕÖµ¡£
COUNT
·µ»Ø×éÖзǿÕÏîµÄÊýÄ¿¡£
Óï·¨
COUNT(aggregate)
COUNT Ê¼ÖÕ·µ»Ø 
Int 
Êý¾ÝÀàÐÍÖµ¡£
COUNTDISTINCT
·µ»Ø×éÖÐijÏîµÄ·Ç¿Õ·ÇÖظ´ÊµÀýÊý¡£
Óï·¨
COUNTDISTINCT(aggregate)
STDev
·µ»ØijÏîµÄ·Ç¿ÕÖµµÄ±ê׼ƫ²î¡£
Óï·¨
STDEV(aggregate)
STDevP
·µ»ØijÏîµÄ·Ç¿ÕÖµµÄ×ÜÌå±ê׼ƫ²î¡£
Óï·¨
STDEVP(aggregate)
VAR
·µ»ØijÏîµÄ·Ç¿ÕÖµµÄ·½²î¡£
Óï·¨
VAR(aggregate)
VARP
·µ»ØijÏîµÄ·Ç¿ÕÖµµÄ×ÜÌå·½²î¡£
Óï·¨
VARP(aggregate)
Ìõ¼þº¯Êý
ÈôÒª²âÊÔÌõ¼þ£¬ÇëʹÓÃÒÔϺ¯Êý£º
IF
Èç¹ûÖ¸¶¨Á˼ÆËã½á¹ûΪ TRUE 
µÄÌõ¼þ£¬½«·µ»ØÒ»¸öÖµ£»Èç¹ûÖ¸¶¨Á˼ÆËã½á¹ûΪ 
FALSE 
µÄÌõ¼þ£¬Ôò·µ»ØÁíÒ»¸öÖµ¡£
Óï·¨
IF(condition, value_if_true, value_if_false)
Ìõ¼þ±ØÐëÊǼÆËã½á¹ûΪ TRUE 
»ò 
FALSE 
µÄÖµ»ò±í´ïʽ¡£Èç¹ûÌõ¼þΪ 
True
£¬Ôò 
Value_if_true 
±íʾ·µ»ØµÄÖµ¡£Èç¹ûÌõ¼þΪ 
False
£¬Ôò 
Value_if_false 
±íʾ·µ»ØµÄÖµ¡£
IN
È·¶¨Ä³ÏîÊÇ·ñÊǼ¯µÄ³ÉÔ±¡£
Óï·¨
IN(item, set)
Switch
¶ÔһϵÁбí´ïʽÇóÖµ²¢·µ»ØÓëÆäÖеÚÒ»¸öΪ True 
µÄ±í´ïʽÏà¹ØÁªµÄ±í´ïʽµÄÖµ¡£
Switch 
¿ÉÒÔÓÐÒ»¸ö»ò¶à¸öÌõ¼þ
/
Öµ¶Ô¡£
Óï·¨
Switch(condition1, value1)
ת»»
ÈôÒª½«Öµ´ÓÒ»ÖÖÊý¾ÝÀàÐÍת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ£¬ÇëʹÓÃÒÔϺ¯Êý£º
INT
½«Öµ×ª»»ÎªÕûÊý¡£
Óï·¨
INT(value)
DECIMAL
½«Öµ×ª»»ÎªÊ®½øÖÆÊý×Ö¡£
Óï·¨
DECIMAL(value)
FLOAT
½«Öµ×ª»»Îª float 
Êý¾ÝÀàÐÍ¡£
Óï·¨
FLOAT(value)
TEXT
½«Êýֵת»»ÎªÎı¾¡£
Óï·¨
TEXT(value)
ÈÕÆÚºÍʱ¼äº¯Êý
ÈôÒªÏÔʾÈÕÆÚ»òʱ¼ä£¬ÇëʹÓÃÒÔϺ¯Êý£º
DATE
·µ»Ø¸ø¶¨Äê¡¢Ô¡


Ïà¹ØÎĵµ£º

sql serverÖн«×ÔÔö³¤ÁйéÁã

Ò»¸öÏîÄ¿Íê³ÉºóÊý¾Ý¿âÖлáÓкܶàÎÞÓõIJâÊÔÊý¾Ý£¬¿ÉÒÔʹÓÃdelete * ½«Êý¾ÝÈ«²¿É¾³ý£¬µ«×ÔÔö³¤ÁУ¨Ò»°ãÊÇÖ÷¼ü£©»ùÊý²»»á¹éÁ㣬ʹÓÃTRUNCATEº¯Êý¿ÉÒÔ½«±íÖÐÊý¾ÝÈ«²¿É¾³ý£¬²¢ÇÒ½«×ÔÔö³¤ÁлùÊý¹éÁã¡£Ò»¶¨Òª×¢Ò⣬±íÖеÄÊý¾ÝÈ«²¿É¾³ýÁË¡£ËüµÄÓï·¨ÈçÏ£º
TRUNCATE TABLE tableName –ÆäÖÐtableNameÖÐËùÒª²Ù×÷µÄÊý¾Ý
......

SQL Serverº¯Êý´óÈ«

--¾ÛºÏº¯Êý
use pubs
go
select avg(distinct price)  --Ëãƽ¾ùÊý
from titles
where type='business'
go 
use pubs
go
select max(ytd_sales)  --×î´óÊý
from titles
go 
use pubs
go
select min(ytd_sales) --×îÐ¡Ê ......

¼òµ¥µ«ÓÐÓõÄSQL½Å±¾

ÐÐÁÐת»»
create table test(id int,name varchar(20),quarter int,profile int)
insert into test values(1,'a',1,1000)
insert into test values(1,'a',2,2000)
insert into test values(1,'a',3,4000)
insert into test values(1,'a',4,5000)
insert into test values(2,'b',1,3000)
insert into test values(2, ......

SQL²åÈëÀýÌâ

--´´½¨±íTongXunLu
CREATE TABLE TongXunLu
 (
 [tName] nvarchar(30),
 [tAddress] nvarchar(50),
 [tEmail] varchar(50)
 )
--´´½¨±í students
CREATE TABLE students
 (
 [sId] int IDENTITY (1, 1) primary key NOT NULL ,
 [sName] varchar (50)   NOT ......

SQL UnionºÍUnion AllµÄʹÓ÷½·¨

¡¡UNIONÖ¸ÁîµÄÄ¿µÄÊǽ«Á½¸öSQLÓï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ ÎÒÃÇ»á²úÉúÕâÑùµÄ¸Ð¾õ£¬UNION¸úJOINËƺõÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNIONµÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT) ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ