SQL中 having语句主要是在什么时候使用,求
展开全部
having与where最大的区别是having 能带聚合函数,而where不可以
select emp_id from t group by emp_id having count(*) = 1 --正确
select emp_id from t group by emp_id where count(*) = 1 --错误
如果用where要达到这个,估计这样
select t1.emp_id from (select emp_id,count(*) as cnt from t group by emp_id)t1 where t1.cnt=1
select emp_id from t group by emp_id having count(*) = 1 --正确
select emp_id from t group by emp_id where count(*) = 1 --错误
如果用where要达到这个,估计这样
select t1.emp_id from (select emp_id,count(*) as cnt from t group by emp_id)t1 where t1.cnt=1
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询