如何创建一个 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
看?这里只有一个查询。并且不需要填充哑虚拟表。
select level*&n from dual connect by level<=10;
在这里,您可以提供您想要的 mutiplicaion 表的任何数字。
将值插入到单个表中,从表中选择两次,在两个表之间不提供连接,然后瞧一个笛卡尔积。
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