mysql 查找一列的所有可能组合 [英] mysql find all the possible combinations of one column

查看:29
本文介绍了mysql 查找一列的所有可能组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表 UserContacts 有一列像

I have the table UserContacts with a column like

  • 1
  • 5
  • 6

我想得到以下结果(这是该列值的所有可能对组合)...(1,5),(1,6),(5,6)

and I want to get the following result (which is all the possible pair combinations of the values of that column)... (1,5),(1,6),(5,6)

有可能吗?

推荐答案

当然,请自行加入:

SELECT a.contact_id a, b.contact_id b
FROM   UserContacts a
  JOIN UserContacts b ON b.contact_id > a.contact_id

sqlfiddle 上查看.

这篇关于mysql 查找一列的所有可能组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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