如何通过聚合函数筛选分组查询?

时间:2017-12-28 13:24:33

标签: sql tsql sql-server-2016

我如何才能显示有预算>的结果? 1000?

SELECT 
     BP_Year
    ,BP_UID
    ,BP_Name
    ,SUM(BP_Budget) as sumBudget  
FROM T_UPS_BudgetPositions 

GROUP BY 
     BP_UID 
    ,BP_Name
    ,BP_Year

1 个答案:

答案 0 :(得分:4)

使用HAVING子句:

SELECT 
     BP_Year
    ,BP_UID
    ,BP_Name
    ,SUM(BP_Budget) as sumBudget  
FROM T_UPS_BudgetPositions 

GROUP BY 
     BP_UID 
    ,BP_Name
    ,BP_Year

HAVING SUM(BP_Budget) > 1000