我有一个 SELECT 语句,它从几个 JOINS 中收集数据,从而产生:
Site Description Status
1 Project 1 Not Started
1 Project 5 In Progress
1 Project 2 Testing
1 Project 12 Complete
1 Project 2 Not Started
2 Project 13 Not Started
2 Project 20 Testing
2 Project 21 In Progress
2 Project 22 In Progress
2 Project 23 Testing
3 Project 24 Not Started
3 Project 25 Not Started
3 Project 26 Testing
3 Project 29 Complete
我想总结每个站点的状态以产生:
Site Not Started In Progress Testing Complete
1 2 1 1 1
2 1 2 2 0
3 2 0 1 1
我应该能够使用“WITH”子句来处理输出。目前,它看起来像这样:
WITH SiteData AS (SELECT data from multiple JOINS...)
SELECT Site, Description, Status FROM SiteData
因此,我不想仅仅显示数据列,而是将其转换为按站点划分的各种状态中的每个项目的计数。
那有意义吗?