sql - 多选语句未执行
问题描述
select
((Select
[Project Name], count(*) as 'PP_Constuction'
from
[dbo].[EriSite_Executive_Report]
where
[Planning Object Name] = 'Construction Start'
and Status like 'Pending Predecessors'
group by
[Project Name]),
(Select
[Project Name], count(*) as 'RTS_Constuction'
from
[dbo].[EriSite_Executive_Report]
where
[Planning Object Name] = 'Construction Start'
and Status like 'Ready%'
group by
[Project Name]),
(Select
[Project Name], count(*) as 'Comple_Constuction'
from
[dbo].[EriSite_Executive_Report]
where
[Planning Object Name] = 'Construction Start'
and Status like 'Completed'
group by
[Project Name])
)
我需要项目名称并根据某些条件(包括标题)进行计数。但它给出了问题。我想输出一些类似下面的东西
Project Name PP_Constuction RTS_Constuction Comple_Constuction
解决方案
You can try using conditional aggregation
Select
[Project Name],
count(case when [Planning Object Name]
='Construction Start' and Status like 'Pending Predecessors' then 1 end) as 'PP_Constuction',
count(case when [Planning Object Name]
='Construction Start' and Status like 'Ready%' then 1 end) as 'RTS_Constuction',
count(case when [Planning Object Name]
='Construction Start' then 1 end) as 'Comple_Constuction'
from [dbo].[EriSite_Executive_Report]
group by [Project Name]
推荐阅读
- java - 我可以在纯 Java 项目中使用使用 Kotlin 协程构建的库吗?
- tensorflow - 如何解释 TensorBoard 损失图?
- networking - 使用 Firefox 时,负载平衡会忽略我一半的节点数
- c - 如何在共享内存数据中完成同步linux c
- python-3.x - 显示除零之外的最小值以及每年的相邻列值+ Python 3+,数据框
- sql-server - 在 SQL Server 中查询以组合表
- apache-spark - hadoop集群上可能存在内存泄漏?(蜂巢,hiveserver2,齐柏林飞艇,火花)
- firebase - 当我通过 expo react native 将图像上传到 firebase 时,它没有显示图像;显示错误加载预览
- php - Wordpress 页面和模板查询
- javascript - 从场景图树循环