mayeye1989
2015-11-18 03:20
采纳率: 54.5%
浏览 1.4k

如何用SQL实现这个功能

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

8条回答 默认 最新

  • _BenChen 2015-11-18 08:50
    已采纳

    select 雇员id from 雇员 join 顾客 on 顾客.雇员id=雇员.雇员id group by 1 having count(distinct 顾客ID) >=2

    点赞 评论
  • blownewbee 2015-11-18 03:21
     select count(*) as n, cus.*, emp.* from cus, emp where cus.empid = emp.id where n >= 2
    
    点赞 评论
  • 把分全给哥 2015-11-18 03:46

    select distinct from (select b.* from select * from 顾客 as a left join 雇员 as b on a.bid=b.id where sum(b.id)>1)

    点赞 评论
  • beyon2008 2015-11-18 07:14

    group by …… having count(1) > 1

    点赞 评论
  • 种兔子的地瓜 2015-11-18 08:03

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

    点赞 评论
  • purcjame 2015-11-18 08:59

    顾客表中 雇员 、顾客两个字段
    用下面语句就可以了
    SELECT 雇员,count(*) FROM 顾客表 GROUP BY 雇员 HAVING count(*)>1

    点赞 评论
  • 吟风笛 2015-11-18 11:57

    雇员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)

    点赞 评论
  • Be_Proud 2015-11-20 15:59

    select count(*) as n, cus.*, emp.* from cus, emp where cus.empid = emp.id where n >= 2

    点赞 评论

相关推荐 更多相似问题