프로그램 사용/postgreSQL
sql combination 생성하기
구차니
2020. 1. 13. 13:24
원래 글에서 응용해서 만들어 본 예제
4*3=12 개 나오는게 맞...겠지? 순열과 조합부터 다시 봐야하나 헷갈리네
select t1, t2 from (select unnest(array['a','b','c','d'])) as t1 join (select unnest(array['1','2','3'])) as t2 on t1 <> t2 |
[링크 : https://stackoverflow.com/questions/31129507/postgres-query-to-create-combinations]
t1과 t2가 동일 데이터가 있으면 안되기에 on에 조건을 true로 주면 문제없이 되긴 한다.
select t1, t2 from (select unnest(array['a','b'])) as t1 join (select unnest(array['1','2','3','a','as'])) as t2 on true |
+
위의 예제에서 join on.. 대신 cross join 해도 되는 듯 하다
select t1, t2 from (select unnest(array['a','b','c','d'])) as t1 cross join (select unnest(array['1','2','3'])) as t2 |
[링크 : https://www.essentialsql.com/cross-join-introduction/]