declare @t table
(
driver varchar(20),
roadband varchar(20),
category varchar(20),
points int
)
INSERT INTO @T VALUES( 'Dan' ,'20 Mph','CAT1',58)
INSERT INTO @T VALUES( 'Dan' ,'20 Mph', 'CAT2', 0)
INSERT INTO @T VALUES( 'Dan' ,'20 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'Dan' ,'30 Mph', 'CAT1', 102)
INSERT INTO @T VALUES( 'Dan' ,'30 Mph', 'CAT2', 30)
INSERT INTO @T VALUES( 'Dan' ,'30 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'Dan' ,'40 Mph', 'CAT1', 6)
INSERT INTO @T VALUES( 'Dan' ,'40 Mph', 'CAT2', 3)
INSERT INTO @T VALUES( 'Dan' ,'40 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'Dan' ,'50 Mph', 'CAT1', 5)
INSERT INTO @T VALUES( 'Dan' ,'50 Mph', 'CAT2', 0)
INSERT INTO @T VALUES( 'Dan' ,'50 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'Dan' ,'60 Mph', 'CAT1', 0)
INSERT INTO @T VALUES( 'Dan' ,'60 Mph', 'CAT2', 0)
INSERT INTO @T VALUES( 'Dan' ,'60 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'Dan' ,'70 Mph', 'CAT1', 0)
INSERT INTO @T VALUES( 'Dan' ,'70 Mph', 'CAT2', 0)
INSERT INTO @T VALUES( 'Dan' ,'70 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'John' ,'20 Mph', 'CAT1', 6)
INSERT INTO @T VALUES( 'John' ,'20 Mph', 'CAT2', 0)
INSERT INTO @T VALUES( 'John' ,'20 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'John' ,'30 Mph', 'CAT1', 1228)
INSERT INTO @T VALUES( 'John' ,'30 Mph', 'CAT2', 654)
INSERT INTO @T VALUES( 'John' ,'30 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'John' ,'40 Mph', 'CAT1', 196)
INSERT INTO @T VALUES( 'John' ,'40 Mph', 'CAT2', 117)
INSERT INTO @T VALUES( 'John' ,'40 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'John' ,'50 Mph', 'CAT1', 6)
INSERT INTO @T VALUES( 'John' ,'50 Mph', 'CAT2', 14)
INSERT INTO @T VALUES( 'John' ,'50 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'John' ,'60 Mph', 'CAT1', 0)
INSERT INTO @T VALUES( 'John' ,'60 Mph', 'CAT2', 0)
INSERT INTO @T VALUES( 'John' ,'60 Mph', 'CAT3', 0)
INSERT INTO @T VALUES( 'John' ,'70 Mph', 'CAT1', 0)
INSERT INTO @T VALUES( 'John' ,'70 Mph', 'CAT2', 0)
INSERT INTO @T VALUES( 'John' ,'70 Mph', 'CAT3', 0)
我需要转向Roadband
和Category
..
我已经写了查询..需要一些帮助..
select * from
(
select
Driver, ROADBAND, category,SUM(points) as Points
from @t
where DRIVER is not null
group by DRIVER ,ROADBAND,CATEGORY
) main
pivot
(
sum(Points)
for ROADBAND in ([20 Mph],[30 Mph],[40 Mph],[50 Mph],[60 Mph],[70 Mph])
) pq
现在如何通过路带对每个类别进行支点。
请帮忙。