如何用SQL实现这个功能

在ORACLE SQL中,有两个TABLE,一个是顾客,一个是雇员
每个雇员有一个或多个顾客,
如何筛选出有多于或者等于2个顾客的雇员?

8个回答

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)

select count( ) from 顾客 group by 雇员 having count() > 1

group by …… having count(1) > 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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问