数据库中差集的使用(Except/Minus/NOT IN/Left Join)

MINUS,比较两个查询的结果,返回在第一个查询结果集中,但不是第二个查询结果集中的行记录,也就是说不包含两个查询返回集合的相交部分。

请注意

某些数据库系统中,例如Microsoft SQLServer,PostgreSQL等,使用Except运算符来实现相同的功能。在Oracle中,使用MINUS运算符。在MySQL中不支持MINUS运算符,但是可以通过Left JOIN连接或者NOT IN运算符来实现

数据库中差集的使用

<!-- 查询当前用户所在单位的用户,当前用户所在单位具有项目负责人权限的用户,做差集 -->
    (select t1.*

from act_id_user t1

left join userInfo t3 on t1.id_ = t3.id_

where t3.deptid = #{deptID})

minus

(select t1.*

from act_id_user t1

left join act_id_membership t2 on t1.id_ = t2.user_id_

left join userInfo t3 on t1.id_ = t3.id_

where t2.group_id_ = 'G0004' and t3.deptid = #{deptID})

MySQL中的差集实现可以参考:http://www.yiibai.com/mysql/minus.html

相关文章:

  • 2022-12-23
  • 2021-12-08
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
猜你喜欢
  • 2021-06-01
  • 2021-05-17
  • 2021-07-22
  • 2021-09-10
  • 2022-01-01
  • 2021-12-09
  • 2022-02-24
相关资源
相似解决方案