用于计算分组值的SQL列

时间:2017-09-25 14:16:37

标签: sql-server tsql group-by count sum

我希望显示作业表中按customer_id分组的作业数量是多少。如果approval_date不为null,则确定批准。因此,如果总共有12个工作岗位,我想表明7个工作被批准了。如果批准日期为空,则不批准该作业。

select   
  c.customer_name
  ,count(*) as counts
  , -- i want to add a column here that tells me which jobs have (j.approval_date is not null)
from job j
join customer c on j.customer_id = c.customer_id
group by c.customer_name

下面的代码给出了语法错误:

,count(approval_date is not null) as is_approved

1 个答案:

答案 0 :(得分:2)

你可以使用条件总和:

DataGrid