aboutsummaryrefslogtreecommitdiff
path: root/challenge-140/luca-ferrari/postgresql/ch-2.sql
blob: d7200535c30d293bc6f79610e2503b53ef21f3b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
CREATE OR REPLACE FUNCTION f_multiplication_table( i int, j int, k int )
RETURNS int
AS $CODE$

WITH RECURSIVE a AS (
     SELECT 1 as x
     UNION
     SELECT x + 1 FROM a
     WHERE  x < i
)
, b AS (
    SELECT 1 as y
    UNION
    SELECT y + 1 FROM b
    WHERE  y  < j
)
, product AS ( SELECT x * y FROM a, b ORDER BY 1 )

select * from product limit 1 offset k;

$CODE$
LANGUAGE SQL;