如何过滤sql表中的两列或三列都相同的数据,显示的是相同的数据,不相同的不显示
展开全部
可以通过group by having count(*) > 1来实现
如select col1,col2 from table1 group by col1,col2 having count(*) > 1
如果表的数据列不只是col1,col2且要显示所有的列则可以
select a.* from table1 a join (
select col1,col2 from table1 group by col1,col2 having count(*) > 1 ) as b
on a.col1 = b.col1 and a.col2 = b.col2
如select col1,col2 from table1 group by col1,col2 having count(*) > 1
如果表的数据列不只是col1,col2且要显示所有的列则可以
select a.* from table1 a join (
select col1,col2 from table1 group by col1,col2 having count(*) > 1 ) as b
on a.col1 = b.col1 and a.col2 = b.col2
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询