【发布时间】:2014-03-26 03:44:59
【问题描述】:
我有以下 sql 查询:
Select Invoices.ID, count(*) invoices
From
Customers.ID F
Inner join Invoices p
On P.ID=F.ID and f.ID = 1
group by p.ID
GO
我想要做的是在 p.ID 分组之后的 if 语句中使用 count() 发票,但是我似乎无法找到获得该值的方法。我知道我可以通过消除 group by 子句来计算行数,但我真的更希望得到 count() invoices 值。
Select Invoices.ID, count(*) invoices
From
Customers.ID F
Inner join Invoices p
On P.ID=F.ID and f.ID = 1
group by p.ID
if ("value from count(*) invoices) = 0
do some stuff here
else
do some other stuff here
GO
感谢您的帮助。 西蒙
【问题讨论】:
标签: sql sql-server-2008 select group-by sql-server-2012