本文主要是介绍having()闲谈,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在sql中使用group 分组以后还想对结果进行筛选的话,就需要用到having()
例1:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
例2:
SELECT Customer,SUM(OrderPrice) FROM Orders
WHERE Customer='Bush' OR Customer='Adams'
GROUP BY Customer
HAVING SUM(OrderPrice)>1500
可见having后面一般都是聚合函数的筛选,别的筛选条件在前面的where语句中and连用就好
当然,having后面也可以用and或者or连用条件
例3:
select count(f_fund_id),count(f2) from table_name group by f_fund_id ,f2 having count(f_fund_id)>1 and count(f2)>3
所以可以理解为,where是在进行group by前的筛选,而having()就是对group by 后的又一次筛选
这篇关于having()闲谈的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!