你好我有关于枢轴的问题:
我有2张桌子
一个是奖励
CREATE TABLE [dbo].[Award](
[awardID] [int] IDENTITY(1,1) NOT NULL,
[typeID] [int] NOT NULL,
[awardYear] [char](4) NULL,
[nominatorID] [varchar](16) NULL,
[nomineeID] [varchar](16) NULL,
[nomineeName] [varchar](100) NULL,
[referenceID] [varchar](16) NULL,
[dateCreated] [datetime] NULL,
[dateSubmitted] [datetime] NULL,
[awardStatus] [varchar](50) NULL,
[hide] [bit] NULL,
[groupID] [int] NULL,
CREATE TABLE [dbo].[AwardRating](
[ratingID] [int] IDENTITY(1,1) NOT NULL,
[awardID] [int] NOT NULL,
[ratedByID] [varchar](16) NULL,
[ratedByName] [varchar](255) NULL,
[rating] [float] NULL,
[ratingDate] [datetime] NULL,
[comments] [text] NULL,
[hide] [bit] NULL,
我希望输出看起来像这样:
http://screencast.com/t/l6qExjSPNSN
在被提名人的下方是评级 每行的第一列是Nominator 每列都是Nominee
我开始写这样的东西但是被卡住了......
SELECT
*
from award
UNPIVOT
( NomineeName in (select distinct nomineeName from award a)up
pivot
(sum(ar.rating)
for NomineeName in (select distinct NomineeName from award a)