SELECT * FROM
(
SELECT Project,STATUS,count(*) AS cnt FROM Defect GROUP BY Project,STATUS
) t
PIVOT(
sum(cnt)
FOR STATUS IN (
[Build Assigned],
[Build Delivered],
[Closed],
[Eng. Build Delivered],
[New],
[Non-Issue],
[Open],[Pending])
) AS pivot_table
with base as
(
SELECT Project
,STATUS
,count(*) AS [count]
FROM Defect
GROUP BY Project
,STATUS
)
select *
from base
pivot (
sum([count])
for base.status in ([Build Delivered],[New],[...],[...])
) as x
order by project
;
select
project,
sum(case when status = 'Build Assigned' then count else 0 end) as Build_Assigned,
sum(case when status = 'Build Delivered' then count else 0 end) as Build_Delivered
from yourTable
group by
project
3条答案
按热度按时间c7rzv4ha1#
你可以试试下面的方法-
e4yzc0pl2#
会是
9bfwbjaz3#
可以使用聚合函数
sum
与case
表达式如下