我如何通过SQL中的聚合字段过滤(where子句)(how can i filter (where clause) by an aggregate field in SQL)
我有以下查询:
Select Distinct Product, sum(Deals) as TotalDeals from Metrics m group by Product我想将查询更改为仅返回TotalDeals = 0的位置。
在查询中使用where子句的最佳方法是什么(而不是在事实之后过滤掉结果集)
I have the following query:
Select Distinct Product, sum(Deals) as TotalDeals from Metrics m group by Productand I want to change the query to only return where TotalDeals = 0.
What is the best way to have this where clause in the query (instead of filtering out of the result set after the fact)
最满意答案
Select Product, TotalDeals FROM ( Select Product, sum(Deals) as TotalDeals from Metrics m group by Product ) Where TotalDeals=0您不需要区分,因为记录按产品分组
要么
Select Product, sum(Deals) as TotalDeals from Metrics m group by Product having sum(Deals) = 0 Select Product, TotalDeals FROM ( Select Product, sum(Deals) as TotalDeals from Metrics m group by Product ) Where TotalDeals=0You don't need distinct as the records are grouped by product
Or
Select Product, sum(Deals) as TotalDeals from Metrics m group by Product having sum(Deals) = 0更多推荐
发布评论