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

sqlÓï¾ä²éѯ

sqlÓï¾ä²éѯ
±í½á¹¹ÊÇÕâÑù£º
ID   ÐÕÃû    ÐÔ±ð
1    ÕÅÈý     ÄÐ
2    ÍõËÄ     ÄÐ
3    ÀöÀö     Å®
4    ÕÅÈý     ÄÐ
5    ÕÔÁø     ÄÐ
6    ¸ß½à     ÄÐ
7    ÍõËÄ     Å®
8    ¸ß½à     Å®
9    ÕÅÈý     Å®
 
ÔõôÄÜÓÃÒ»ÌõSQLÓï¾ä²éѯ³öÈçϵĽá¹û
ÐÕÃû   ÈËÔ±¸öÊý    ÄÐÈËÊý    Å®ÈËÊý    °üº¬ID
ÕÅÈý      3          2         1       1£¬4£¬9
ÍõËÄ      2          1         1       2£¬7
ÀöÀö      1          0         1       3
¸ß½à      2          1         1       6£¬8
ÕÔÁø      1          1         0       5  
  
SELECT * from (SELECT DISTINCT Name,Count(ID) as ÈË員個數,
sum(case when Sex='ÄÐ' then 1 else 0 end) as ÄÐÈË數, 
sum(case when Sex='Å®' then 1 else 0 end) as Å®ÈË數 
from Test group by Name) A
OUTER APPLY(
    SELECT 
        [°üº¬ID]= STUFF(REPLACE(REPLACE(
            (
                SELECT ID from Test N
                WHERE Name = A.Name
                FOR XML AUTO
            ), '<N ID="', ','), '"/>', ''), 1, 1, '')
)N 
 


Ïà¹ØÎĵµ£º

sql group by

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

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ÊÇÎÞ·¨×öµ½µ ......

SQLÓï·¨ÓëÃüÁî


SQLÓï·¨ÓëÃüÁî
SELECT Óï¾ä
SELECT[predicate]{*|table.*|[table.]field [,[table.]field2[,...]]} [AS alias1
[,alias2[,...]]]
from tableexpression [,...][IN externaldatabase]
[WHERE...]
[GROUP BY...]
[HAVING...]
[ORDER BY...]
[WITH OWNERACCESS OPTION]
SELECT Óï¾ä°üÀ¨ÏÂÃ漸¸ö²¿·Ö
predicate ......

³£ÓõÄSQLÓï¾ä

н¨±í£º
create table [±íÃû]
(
[×Ô¶¯±àºÅ×Ö¶Î] int IDENTITY (1,1) PRIMARY KEY ,
[×Ö¶Î1] nVarChar(50) default 'ĬÈÏÖµ' null ,
[×Ö¶Î2] ntext null ,
[×Ö¶Î3] datetime,
[×Ö¶Î4] money null ,
[×Ö¶Î5] int default 0,
[×Ö¶Î6] Decimal (12,4) default 0,
[×Ö¶Î7] image null ,
)
ɾ³ý±í£º
Drop table [±í ......

SQL ServerµÄ¸´ºÏË÷Òýѧϰ

SQL ServerµÄ¸´ºÏË÷Òýѧϰ
¸ÅÒª
ʲôÊǵ¥Ò»Ë÷Òý,ʲôÓÖÊǸ´ºÏË÷ÒýÄØ? ºÎʱн¨¸´ºÏË÷Òý£¬¸´ºÏË÷ÒýÓÖÐèҪעÒâЩʲôÄØ£¿±¾ÆªÎÄÕÂÖ÷ÒªÊǶÔÍøÉÏһЩÌÖÂÛµÄ×ܽᡣ
Ò».¸ÅÄî
µ¥Ò»Ë÷ÒýÊÇÖ¸Ë÷ÒýÁÐΪһÁеÄÇé¿ö,¼´Ð½¨Ë÷ÒýµÄÓï¾äֻʵʩÔÚÒ»ÁÐÉÏ¡£
Óû§¿ÉÒÔÔÚ¶à¸öÁÐÉϽ¨Á¢Ë÷Òý£¬ÕâÖÖË÷Òý½Ð×ö¸´ºÏË÷Òý(×éºÏË÷Òý)¡£¸´ºÏË÷ÒýµÄ´´½¨· ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ