我有一个站点表,我需要从中生成site_id对。 所以我有:
site_id
1
2
3
4
并需要生成以下结果
1 - 2,
1 - 3,
1 - 4,
2 - 3,
2 - 4,
3 - 4
没有网站可以匹配自己,任何一方都可以是其中一个值。 到目前为止,我有以下内容。
select a,b from (select site_id as a, site_id as b) as sites group by a,b;
和
select distinct a,b from (select site_id as a, site_id as b) as sites group by a,b;
此处提出了类似的问题,但是对于matlab matlab question
任何帮助将不胜感激
答案 0 :(得分:1)
这样的东西?
SELECT s1.site_id, s2.site_id
FROM site s1
JOIN site s2
ON s2.site_id > s1.site_id
/* ORDER BY s1.site_id */