SQL server2005ÖÐÓÃpivotʵÏÖÐÐÁÐת»»
--> --> (Roy)Éú³É²âÊÔÊý¾Ý
if not object_id('Class') is null
drop table Class
Go
Create table Class([Student] nvarchar(2),[Course] nvarchar(2),[Score] int)
Insert Class
select N'ÕÅÈý',N'ÓïÎÄ',78 union all
select N'ÕÅÈý',N'Êýѧ',87 union all
select N'ÕÅÈý',N'Ó¢Óï',82 union all
select N'ÕÅÈý',N'ÎïÀí',90 union all
select N'ÀîËÄ',N'ÓïÎÄ',65 union all
select N'ÀîËÄ',N'Êýѧ',77 union all
select N'ÀîËÄ',N'Ó¢Óï',65 union all
select N'ÀîËÄ',N'ÎïÀí',85
Go
¶¯Ì¬:
declare @s nvarchar(4000)
Select @s=isnull(@s+',','')+quotename([Course]) from Class group by[Course]
exec('select * from Class pivot (max([Score]) for [Course] in('+@s+'))b')
Éú³É¾²Ì¬:
select *
from
Class
pivot
(max([Score]) for [Course] in([Êýѧ],[ÎïÀí],[Ó¢Óï],[ÓïÎÄ]))b
Éú³É¸ñʽ:
/*
Student Êýѧ ÎïÀí Ó¢Óï ÓïÎÄ
------- ----------- ----------- ----------- -----------
ÀîËÄ 77 85 65 65
ÕÅÈý 87 90 82 78
(2 ÐÐÊÜÓ°Ïì)
*/
--2000·½·¨:
¶¯Ì¬:
declare @s nvarchar(4000)
set @s=''
Select @s=@s+','+quotename([Course])+'=max(case when [Course]='+quotename([Course],'''')+' then [Score] else 0 end)'
from Class group by[Course]
exec('select [Student]'+@s+' from Class group by [Student]')
Éú³É¾²Ì¬:
select
[Student],
[Êýѧ]=max(case when [Course]='Êýѧ' then [Score] else 0 end),
[ÎïÀí]=max(case when [Course]='ÎïÀí' then [Score] else 0 end),
[Ó¢Óï]=max(case when [Course]='Ó¢Óï' then [Score] else 0 end),
[ÓïÎÄ]=max(case whe
Ïà¹ØÎĵµ£º
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="fw_student">
<resultMap class="com.sias.Student" id="student">
<result column="name" property="na ......
×¼±¸½«Ò»¸öexcel±íµ¼ÈëSQL Server2005Öз¢ÉúÁËÏÂͼµÄ´íÎó£º
ÖØÆôSQL Server2005»¹ÊdzöÏÖÉÏͼµÄ´íÎ󣬽â¾ö·½·¨£¨ÈçÏÂͼ£©£º
ÔÚSQL Server Configuration ManagerÖн«SSIS¼´SQL Server Integration ServicesµÄÊôÐÔÖеÄÄÚÖÃÕË»§¸ÄΪ“±¾µØÏµÍ³”£¬ÖØÆô·þÎñ¼´¿Éµ¼ÈëexcelÁË¡£ ......
¿ìÕÕ¸ôÀë Snapshot Isolation
1¡¢Ð´Èë³ÌÐò²»»á×è°¶ÁÈ¡³ÌÐò
2¡¢ÐµĸôÀë¼¶±ðÌṩÁËÒÔÏÂÓŵ㣺
1) Ìá¸ßÁËÖ»¶ÁÓ¦ÓóÌÐòµÄÊý¾Ý¿ÉÓÃÐÔ
2) ÔÊÐíÔÚOLTP»·¾³ÖÐÖ´ÐзÇ×èÖ¹¶ÁÈ¡²Ù×÷
3) ¿É¶ÔдÈëÊÂÎñ½øÐÐ×Ô¶¯µÄÇ¿ÖÆ³åÍ»¼ì²â
3¡¢ÑÝʾ´úÂë
CREATE DATABASE demo2
GO
USE demo2
ALTER DATABASE demo2 SET allow_snapsho ......
ÅÅÃûº¯ÊýÊÇSQL Server2005мӵŦÄÜ¡£ÔÚSQL Server2005ÖÐÓÐÈçÏÂËĸöÅÅÃûº¯Êý£º
¡¡¡¡1. row_number
¡¡¡¡2. rank
¡¡¡¡3. dense_rank
¡¡¡¡4. ntile
¡¡¡¡Ò»¡¢row_number
¡¡¡¡row_numberº¯ÊýµÄÓÃ;ÊǷdz£¹ã·º£¬Õâ¸öº¯ÊýµÄ¹¦ÄÜÊÇΪ²éѯ³öÀ´µÄÿһÐмǼÉú³ÉÒ»¸öÐòºÅ¡£row_numberº¯ÊýµÄÓ÷¨ÈçÏÂÃæµÄSQLÓï¾äËùʾ£º
¡¡¡¡sel ......
Ò»¡¢Ç°ÑÔ
“ÈËÀàʧȥËÑË÷£¬ÊÀ½ç½«»áÔõÑù?”£¬Í¬Ñù£¬ºÜÄÑÏëÏóÒ»¸öÓµÓм«´óÐÅÏ¢Á¿µÄÐÐÒµÍøÕ¾ÃÅ»§Ã»ÓÐÕ¾ÄÚÈ«ÎÄËÑË÷½«»á³öÏÖÔõÑùµÄ¾ÖÃæ£¬ÍøÕ¾È«ÎļìË÷¶ÔÓÚÍÚ¾òÍøÕ¾ÐÅÏ¢ºÍÕûºÏÍøÕ¾×ÊÔ´µÄ¼ÛÖµÊDz»ÑÔ¶øÓ÷µÄ¡£ÎÒÃÇ¿´µ½£¬Í¨ÓÃÐ͵ÄËÑË÷ÒýÇæÒѾ³ÉΪÁË»¥ÁªÍøÊÀ½çµÄÃÅ»§£¬¶ø¶ÔÓÚÒ»¸öÐÅÏ¢Á¿¼«Æä·á¸»µÄÍøÕ¾¶øÑÔ£¬È«ÍøËÑË÷»òÐ ......