1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SQLで組み合わせを作ってみる

Posted at

1から15の数字を使って要素数7の組み合わせを作る

要はこれ $$ _{15} C _7 $$

WITH element AS(
  SELECT 
    a
  FROM 
    UNNEST(GENERATE_ARRAY(1,15)) AS a
)

SELECT
  e1.a AS a1, 
  e2.a AS a2, 
  e3.a AS a3, 
  e4.a AS a4, 
  e5.a AS a5, 
  e6.a AS a6, 
  e7.a AS a7
FROM
  element AS e1,
  element AS e2,
  element AS e3,
  element AS e4,
  element AS e5,
  element AS e6,
  element AS e7
WHERE 
  e1.a < e2.a
  AND e2.a < e3.a
  AND e3.a < e4.a
  AND e4.a < e5.a
  AND e5.a < e6.a
  AND e6.a < e7.a

もうちょっとスマートにしたい。
とは言えこれができたからと言って利用用途が思いついてるわけではない。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?