結合やサブクエリなどを使用せずに乗算表を出力する SELECT クエリを作成するにはどうすればよいですか? いくつかの新しいサポート テーブルを使用することができます。
更新:
select
x " ",
x*x1 "1", x*x2 "2", x*x3 "3", x*x4 "4", x*x5 "5", x*x6 "6", x*x7 "7", x*x8 "8", x*x9 "9", x*x10 "10"
from num, res
where rownum < 11;
SELECT
level AS C,
1*level AS R1,
2*level AS R2,
3*level AS R3,
4*level AS R4,
5*level AS R5,
6*level AS R6,
7*level AS R7,
8*level AS R8,
9*level AS R9,
10*level AS R10
FROM dual CONNECT BY level < 11
見る?ここでは、クエリは 1 つだけです。ばかげたダミーのテーブルを埋める必要はありません。
select level*&n from dual connect by level<=10;
ここでは、マルチプリケーションテーブルにする任意の数を指定できます。
値を 1 つのテーブルに挿入し、テーブルから 2 回選択し、2 つのテーブル間を結合せず、デカルト積を作成します。
CREATE TABLE Multiplctable(c1 int ,c2 int ,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int,c9 int ,c10 int,c11 int,c12 int)
DECLARE @Loopcon int;--LOOP CONTROLL
Set @Loopcon=1;
WHILE(@Loopcon<=12)
BEGIN;
INSERT INTO Multiplctable
VALUES(@Loopcon*1,@Loopcon*2,@Loopcon*3,@Loopcon*4,@Loopcon*5,@Loopcon*6,
@Loopcon*7,@Loopcon*8,@Loopcon*9,@Loopcon*10,@Loopcon*11,@Loopcon*12);
SET @Loopcon=@Loopcon+1;
END;
SELECT M.c1 [1],M.c2 [2],M.c3 [3],M.c4 [4],M.c5 [5],M.c6 [6],M.c7 [7],M.c8 [8],M.c9 [9],M.c10 [10],M.c11 [11],M.c12 [12]
FROM Multiplctable M