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

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


Ïà¹ØÎĵµ£º

sql_map_config.xml(SQL Map»·¾³Îļþ)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
 "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
 <!-- ÅäÖúÍÓÅ»¯SQL Map½âÎöʵÀýµÄÉ趨 -->
 <settings cacheModelsEnabled=" ......

¸ßÈËÇóÖú£¬SQLÎÊÌ⣡

ԭʼÊý¾Ý
 
  
TERMINAL_ID
MAXDATE
TERMINAL_ID
OCCUR_DATE_TIME
TROUBLE_CD
  
1
12345
20100401102754
12345
20100401102754
210
  
2
12345
20100401102754
12345
20100401102754
211
  
3
12345
20100401102754
12345
20100401102754
?09
......

Sql server2005µ¼Èëexcelʱ³öÏÖÒ»¸ö´íÎó

×¼±¸½«Ò»¸öexcel±íµ¼ÈëSQL Server2005Öз¢ÉúÁËÏÂͼµÄ´íÎó£º
ÖØÆôSQL Server2005»¹ÊdzöÏÖÉÏͼµÄ´íÎ󣬽â¾ö·½·¨£¨ÈçÏÂͼ£©£º
ÔÚSQL Server Configuration ManagerÖн«SSIS¼´SQL Server Integration ServicesµÄÊôÐÔÖеÄÄÚÖÃÕË»§¸ÄΪ“±¾µØÏµÍ³”£¬ÖØÆô·þÎñ¼´¿Éµ¼ÈëexcelÁË¡£ ......

Entity Sql ¹¤¾ß

Entity sql ²éѯ·ÖÎöÆ÷
1¡¢eSqlBlast for VS 2008 SP1 ¿ªÔ´
download£ºhttp://code.msdn.microsoft.com/esql/Release/ProjectReleases.aspx?ReleaseId=991
Ó÷¨£ºhttp://www.cnblogs.com/xiaomi7732/archive/2008/09/09/1287952.html
2¡¢LINQPad
Ö÷Ò³ http://www.linqpad.net/
²»½öÖ§³Ö entity sql £¬»¹Ö§³ÖLinq £¬s ......

SQL Server 2005È«ÎļìË÷¼¼ÊõÔÚÍøÕ¾ÉϵÄÓ¦ÓÃʵ¼


Ò»¡¢Ç°ÑÔ
“ÈËÀàʧȥËÑË÷£¬ÊÀ½ç½«»áÔõÑù?”£¬Í¬Ñù£¬ºÜÄÑÏëÏóÒ»¸öÓµÓм«´óÐÅÏ¢Á¿µÄÐÐÒµÍøÕ¾ÃÅ»§Ã»ÓÐÕ¾ÄÚÈ«ÎÄËÑË÷½«»á³öÏÖÔõÑùµÄ¾ÖÃæ£¬ÍøÕ¾È«ÎļìË÷¶ÔÓÚÍÚ¾òÍøÕ¾ÐÅÏ¢ºÍÕûºÏÍøÕ¾×ÊÔ´µÄ¼ÛÖµÊDz»ÑÔ¶øÓ÷µÄ¡£ÎÒÃÇ¿´µ½£¬Í¨ÓÃÐ͵ÄËÑË÷ÒýÇæÒѾ­³ÉΪÁË»¥ÁªÍøÊÀ½çµÄÃÅ»§£¬¶ø¶ÔÓÚÒ»¸öÐÅÏ¢Á¿¼«Æä·á¸»µÄÍøÕ¾¶øÑÔ£¬È«ÍøËÑË÷»òÐ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ