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

SQL ServerÖеÄÐÐÁе¹Öü¼ÇÉ

ÐÐÁе¹ÖÃÔÚsql serverÖÐÊÇÒ»Öֺܳ£¼ûµÄ¼¼ÇÉ£¬ÔÚ×öÓ¦ÓÃϵͳµÄʱºò£¬¾­³£ÐèÒª×öһЩͳ¼Æ¹¦ÄܱÜÃâ²»ÁËʹÓÃÐÐÁе¹ÖÃÕâ¸ö¼¼ÇÉ£¬ÎÒССµÄ×öÁËÒ»ÏÂ×ܽ᣺
µÚÒ»ÖÖ£ºsql server 2000ÖÐʹÓÃcase½øÐÐÐÐÁе¹ÖÃ
create table RowCellConvertTest
(
 grade varchar(50),
 sex varchar(50),
 studentCount int
)
go
insert into RowCellConvertTest
select 'Ò»Ä꼶','ÄÐ',100 union all
select 'Ò»Ä꼶','Å®',200 union all
select '¶þÄ꼶','ÄÐ',100 union all
select '¶þÄ꼶','Å®',100 union all
select 'ÈýÄ꼶','ÄÐ',200 union all
select 'ÈýÄ꼶','Å®',200
go
select * from RowCellConvertTest
go
--ÀûÓÃSQL Server 2000µÄcase½«ÐÐת»»³ÉÁÐ
declare @sql varchar(max)
set @sql = 'select grade'
select @sql=@sql+ ',sum(case when sex = '''+sex+''' then studentCount else '''' end) as '''+sex+'''' from RowCellConvertTest group by sex
--select @sql = substring(@sql,2,len(@sql))
--print @sql
select  @sql = @sql +'from RowCellConvertTest group by grade'
exec(@sql)
go
drop table RowCellConvertTest
go
     
Ч¹û£º
 
     
     
µÚ¶þÖÖ:
--ÀûÓÃSQL Server 2005ÐÂÌØÐÔpivot½«ÐÐת»»³ÉÁÐ
select grade,ÄÐ,Å®
from
(
select  studentCount, sex, grade from RowCellConvertTest
) p
PIVOT
(
 sum (studentCount)
 FOR sex IN
 (ÄÐ,Å®)
) AS pvt
ORDER BY pvt.grade;
     
     
¸½¼Ó£º½«ÁÐת»»³ÉÐÐ
     
--½«ÁÐת»»³ÉÐÐ
create table CellRowConvertTest
(
 grade varchar(50),
 ÄÐ varchar(50),
 Å® varchar(50)
)
go
insert into CellRowConvertTest
select 'Ò»Ä꼶',100,200 union all
select '¶þÄ꼶',100,100 union all
select 'ÈýÄ꼶',200,200
go
select * from CellRowConvertTest
go
select grade,sex,studentCount
from
(
 select grade,ÄÐ,Å® from CellRowConvertTest
) as p
unpivot
(
 studentCount for sex in (ÄÐ,Å®)
) as unpvt;
go
drop table CellRowConvertTest
go
     
Ч¹û:
 


Ïà¹ØÎĵµ£º

SQL ³£Óú¯Êý ±Ê¼Ç Garin Zhang

SQL³£Óú¯Êý£º
1. ASCII()£º·µ»Ø×Ö·û´®×î×ó¶Ë×Ö·ûµÄASCIIÂë¡£
2. CHAR()£º½«ASCIIת»»³É×Ö·û¡£(0~255)
3. LOWER()ºÍUPPER()¡£
4. STR()£º°ÑÊýÖµÐÍÊý¾Ýת»»Îª×Ö·ûÐÍÊý¾Ý
    SRT(<float_expression>[,length[,<decimal>]])
LTRIM()°Ñ×Ö·û´®Í·²¿¿Õ¸ñÈ¥µô£¬RTRIM()°Ñ×Ö·û´®Î²¿Õ¸ñÈ¥µô¡£
È¡× ......

ʹÓÃsqlÓï¾ä»ñµÃµ±Ç°ÔÂÌìÊý


 Ê¹ÓÃsqlÓï¾ä»ñµÃµ±Ç°ÔÂÌìÊý
   --»ñµÃµ±ÔÂÌìÊý  
    select day(dateadd(mm,1,getdate())-day(getdate())) as ±¾ÔÂÌìÊý ;  
    select getdate() as µ±Ç°ÈÕÆÚ;  
  &nb ......

Éî¶È¶Ô±ÈOracleÓëSQL Server——µÚ¶þ²¿·Ö

Êý¾Ý¿âʵÀý½á¹¹ ÊÂÎñÒ»ÖÂÐÔ(Transactional Consistency)ºÍ»ùÓÚʱ¼äµãµÄ»Ö¸´(Point-in-time Recovery) ϵͳԪÊý¾Ý
topÊý¾Ý¿âʵÀý½á¹¹
µ±OracleʵÀýÆô¶¯Ö®ºó£¬Ëù¿´µ½µÄ¾ÍÊÇÔÚ·þÎñÆ÷ÄÚ´æÉϵÄÒ»¸ö¸ö²»Í¬ÄÚ´æ¿é¼ÓÉϲúÉúµÄÓëÕâЩÄÚ´æ½»»¥µÄºǫ́½ø³Ì¡£OracleÎĵµ½«ÕâЩÄÚ´æ½á¹¹ºÍ½ø³ÌÊյĺÜÏêϸ¡£
ÓÉOracleʵÀýËùÕ¼ÓõÄÄÚ´æ¿é³ ......

Éî¶È¶Ô±ÈOracleÓëSQL Server——µÚÈý²¿·Ö

Æô¶¯ÓëÅäÖòÎÊý ¸ü¸ÄϵͳԪÊý¾ÝºÍ²ÎÊýÅäÖà ¶¯Ì¬ÊÓͼ ´æ´¢µÄÎïÀíºÍÂß¼­½á¹¹ Æô¶¯ºÍ¹Ø±Õ
topÆô¶¯ÓëÅäÖòÎÊý
ÔÚSQL Server°²×°µÄʱºò£¬Í¬Ê±Ò²»áÍùWindows×¢²á±íÀïÃæÌí¼ÓһЩ¼Ç¼£¬ÕâЩע²á±í¼üÖµÖ¸¶¨ÁËʵÀýËùÐèÒªµÄ¸÷ÖÖ²ÎÊý¡£±ÈÈ磬ÓеÄ×¢²á±í¼üÖµÖ¸¶¨ÁË´íÎóÈÕÖ¾µÄ±£´æĿ¼£¬ÁíÍâµÄÖ¸¶¨ÁËĬÈϵı¸·ÝĿ¼µÈµÈ¡£SQL ServerÔÚÔ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ