选择不同的对mysql [英] Selecting distinct pair mysql

查看:45
本文介绍了选择不同的对mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择A列和B列中具有相同值的行.

I would like to select the rows that has the same values across column A and column B.

例如,如果我的桌子是

A  B

1  2
3  4
1  2
4  5

输出应为

A  B
1  2

A. Select Distinct A,B from table

选择表中的所有值.

B. Select Distinct (A,B) from table

告诉我Distinct函数只能取一个值.

tells me that Distinct function can take only one value.

C. Select A,B from table group by A,B

选择表中的所有值(类似于A).

Selects all the values in the table (Similar to A).

问题类似于选择不同的组合. 但是答案提示那行不通.

The question is similar to Selecting Distinct combinations. but the answer suggested there doesn't work.

推荐答案

您只需要具有重复项的行.您可以使用HAVING子句基于聚合函数来过滤数据的分组":

You want only the rows which have duplicates. You can use the HAVING clause to filter "groupings" of data based on aggregation functions:

SELECT   A,B
FROM     tbl
GROUP BY A,B
HAVING   COUNT(*) > 1

这篇关于选择不同的对mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆