sql-server – 从SQL Server中选择具有匹配列的行
发布时间:2021-02-27 21:30:54 所属栏目:MsSql教程 来源:网络整理
导读:我很确定这很简单,但我尝试的每个例子都失败了.我想查询这样的表 ID Part_Type Station_Type--- --------- ------------1 5 2342 5 8463 5 2344 6 5855 6 5856 7 465 并返回行1和3,以及4和5. 也就是说,我想返回两列匹配的行. 它类似于这个问题:SO Question但
我很确定这很简单,但我尝试的每个例子都失败了.我想查询这样的表 ID Part_Type Station_Type --- --------- ------------ 1 5 234 2 5 846 3 5 234 4 6 585 5 6 585 6 7 465 并返回行1和3,以及4和5. 谢谢 解决方法您可以使用以下内容:select t1.id,t1.part_type,t1.station_type from yourtable t1 where exists (select part_type,station_type from yourtable t2 where t1.part_type = t2.part_type and t1.station_type = t2.station_type group by part_type,station_type having count(id) > 1) 见SQL Fiddle with Demo (编辑:威海站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |