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

Sql Server ×Ö·û´®¾ÛºÏº¯Êý

 Sql Server ÓÐÈçϼ¸Ö־ۺϺ¯ÊýSUM¡¢AVG¡¢COUNT¡¢COUNT(*)¡¢MAX ºÍ MIN£¬µ«ÊÇÕâЩº¯Êý¶¼Ö»ÄܾۺÏÊýÖµÀàÐÍ£¬ÎÞ·¨¾ÛºÏ×Ö·û´®¡£Èçϱí:AggregationTable
Id Name
1 ÕÔ
2 Ç®
1 Ëï
1 Àî
2 ÖÜ
Èç¹ûÏëµÃµ½ÏÂͼµÄ¾ÛºÏ½á¹û
Id Name
1 ÕÔËïÀî
2 Ç®ÖÜ
ÀûÓÃSUM¡¢AVG¡¢COUNT¡¢COUNT(*)¡¢MAX ºÍ MINÊÇÎÞ·¨×öµ½µÄ¡£ÒòΪÕâЩ¶¼ÊǶÔÊýÖµµÄ¾ÛºÏ¡£²»¹ýÎÒÃÇ¿ÉÒÔͨ¹ý×Ô¶¨Ò庯ÊýµÄ·½Ê½À´½â¾öÕâ¸öÎÊÌâ¡£
1.Ê×ÏȽ¨Á¢²âÊÔ±í£¬²¢²åÈë²âÊÔÊý¾Ý£º
view plaincopy to clipboardprint?
create table AggregationTable(Id int, [Name] varchar(10))  
go  
insert into AggregationTable  
    select 1,'ÕÔ' union all  
    select 2,'Ç®' union all  
    select 1,'Ëï' union all  
    select 1,'Àî' union all  
    select 2,'ÖÜ' 
go 
create table AggregationTable(Id int, [Name] varchar(10))
go
insert into AggregationTable
 select 1,'ÕÔ' union all
 select 2,'Ç®' union all
 select 1,'Ëï' union all
 select 1,'Àî' union all
 select 2,'ÖÜ'
go
2.´´½¨×Ô¶¨Òå×Ö·û´®¾ÛºÏº¯Êý
view plaincopy to clipboardprint?
Create FUNCTION AggregateString  
(  
    @Id int 
)  
RETURNS varchar(1024)  
AS  
BEGIN  
    declare @Str varchar(1024)  
    set @Str = '' 
    select @Str = @Str + [Name] from AggregationTable  
    where [Id] = @Id  
    return @Str  
END  
GO 
Create FUNCTION AggregateString
(
 @Id int
)
RETURNS varchar(1024)
AS
BEGIN
 declare @Str varchar(1024)
 set @Str = ''
 select @Str = @Str + [Name] from AggregationTable
 where [Id] = @Id
 return @Str
END
GO
3.Ö´ÐÐÏÂÃæµÄÓï¾ä£¬²¢²é¿´½á¹û
view plaincopy to clipboardprint?
select dbo.Aggregate


Ïà¹ØÎĵµ£º

oracle PL/SQL Öг£Á¿ºÍ±äÁ¿µÄÉùÃ÷

 
Ò»¡¢³£ÓÃÊý¾ÝÀàÐÍ£º
Number£ºÊý×ÖÀàÐÍ
Int£ºÕûÊýÐÍ
Pls_integer£ºÕûÊýÐÍ£¬²úÉúÒç³öµÄ´íÎó
Binary_integer£ºÕûÊýÐÍ
Char£º¶¨³¤×Ö·û£¬×255¸ö×Ö·û
Varchar2£º±ä³¤×Ö·û£¬×2000¸ö×Ö·û
Long£º±ä³¤×Ö·û£¬×2GB
Date£ºÈÕÆÚÐÍ
Boolean£º²¼¶ûÐÍ
¶þ¡¢¶¨Òå³£Á¿
¸ñʽ£º³£Á¿Ãû   constant &nbs ......

ÓÃC#¶ÁSQL SERVERµ½¿ØÖÆÌ¨µÄ¼òµ¥Ê¾Àý

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//sqlserverÉí·ÝÑéÖ¤
//string sqlconn = "ser ......

´«ÖDz¥¿Íjavaѧϰ sql¼òµ¥²éѯÓï¾ä

½ñÌìÎÒѧϰÁËsqlµÄ¼òµ¥²éѯÓï¾ä£¬
 
һЩ»ù±¾µÄ¸ÅÄ
1                  ϵͳȨÏÞ£ºÊý¾Ý¿âÖеĶÔÏó£¬ ±í£¬´´½¨±í£¬É¾³ý±í
2           ¶ÔÏóȨÏÞ£º¶ÔÊý¾ÝµÄÔö¡¢É¾¡¢¸Ä¡¢²é¡ ......

sql group by

group byÖ÷ÒªÊÇÓÃÀ´·Ö×éµÄ£¬Ôõô¸ö·Ö×éÄØ£¿
ÒÔÏÂÓÃÁ½¸öÀý×Ó˵Ã÷Á½¸öʹÓ÷½Ã棬1ÊǺÏÀíµÄ·µ»ØºÏ¼ÆÖµ£¨·ÀÖ¹µÑ¿¨¶û»ýÏÖÏ󣩣¬2ÊÇÓ÷Ö×éÀ´ÕÒ³öÖØ¸´µÄ¼Ç¼
====================================================================
¡ï¡ï¡ïÀý×Ó1£º¼ÙÈçÓÐÕâôһ¸ö±í£ºtab_1£¬ËüÓÐÁ½¸ö×ֶΣºxm¡¢gzlb¡¢je£¨ÐÕÃû¡¢¹¤×ÊÀà±ð¡¢½ð¶î£© ......

Èճ̰²ÅÅÉú³ÉµÄsqlÓï¾ä

select *
from
(select [id]=row_number() over (order by getdate()),
        date=convert(varchar(8),dateadd(dd,number,'2010-01-01'),112)
        from
        (select number from master..spt ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ