在ORACLE SQL中,有两个TABLE,一个是顾客,一个是雇员
每个雇员有一个或多个顾客,
如何筛选出有多于或者等于2个顾客的雇员?
select 雇员id from 雇员 join 顾客 on 顾客.雇员id=雇员.雇员id group by 1 having count(distinct 顾客ID) >=2
select count(*) as n, cus.*, emp.* from cus, emp where cus.empid = emp.id where n >= 2
select distinct from (select b.* from select * from 顾客 as a left join 雇员 as b on a.bid=b.id where sum(b.id)>1)
group by …… having count(1) > 1
select count( ) from 顾客 group by 雇员 having count() > 1
顾客表中 雇员 、顾客两个字段
用下面语句就可以了
SELECT 雇员,count(*) FROM 顾客表 GROUP BY 雇员 HAVING count(*)>1
雇员bd_employee {id,name} 顾客表 bd_customer {id,name,employeeid }
结果拥有顾客数量大于1个的雇员信息
select emp.id,emp.name from bd_employee emp where emp.id in(select employeeid from bd_customer group by employeeid having count(*) >1)
select count(*) as n, cus.*, emp.* from cus, emp where cus.empid = emp.id where n >= 2