sql 查出相同的记录 并把相同记录 显示在一起

select c.workunit unitname,a.positionid,a.positiontype,a.isfirst,a.mastersort,a.directoraudit, c.writername,d.bookname,e.orgname unitid,b.positiontype applypositiontype, b.auditstate,b.editauditstate,b.appposiid,c.writerid,d.bookid,b.materid,b.isreceivedpaper, case when a.positiontype='' or a.positiontype is null then 1 else 0 end sort from teach_positionset a right join teach_applyposition b on b.appposiid = a.appposiid left join writer_declaration c on c.writerid=b.writerid left join teach_bookinfo d on d.bookid=b.bookid left join ba_organize e on e.orgid=c.unitid where 1=1 and b.auditstate=11 and b.isreceivedpaper=1 and d.bookid="1815f93a80da4427853a1a2a9faf06e2"
AND b.positiontype in(SELECT b.positiontype applypositiontype FROM teach_applyposition b group by b.positiontype having count(b.positiontype)>1) GROUP BY appposiid ORDER BY sort,a.positiontype,a.mastersort,b.positiontype

SELECT b.positiontype applypositiontype FROM teach_applyposition b group by b.positiontype having count(b.positiontype)>1的结果是

原文地址:https://www.cnblogs.com/niuxi/p/7244029.html