首页 > 解决方案 > 如何在sql中实现以下要求

问题描述

在此处输入图像描述我有如下表

结果集应包含 4,5,因为它的计数为 (c2) 和 (c3) >1

标签: sql

解决方案


您可以使用exists

select t.*
from table t
where exists (select 1 from table t1 where t1.col2 = t.col2 and t1.col1 <> t.col1);

推荐阅读