select * from table where fleet_cd = p65 and fleet_cd=p67 不过你实例数据里好像没这样的记录
staff_num是用户id? 是否是找出fleet_cd中有p65也有p67的staff_numselect distinct staff_num from table1 a where fleet_cd='p65' and exists(select 1 from table1 where staff_num=a.staff_num and fleet_cd='p67')
不过你实例数据里好像没这样的记录
是否是找出fleet_cd中有p65也有p67的staff_numselect distinct staff_num from table1 a
where fleet_cd='p65'
and exists(select 1 from table1
where staff_num=a.staff_num and fleet_cd='p67')
--有这两个数据行存在就行?--是 staff_num字段相等,但fleet_cd 等于p65 又等于p67 的有且只有两条记录??
--是这个意思吗?