如何创建将输出multiplication table的SELECT查询 没有使用像连接或子查询这样的东西?可以使用一些新的支持表。
UPD:
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;
答案 0 :(得分:1)
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 :(得分:0)
将值插入到单个表中,从表中选择两次,在两个表之间不提供连接,并保留笛卡尔积。
答案 2 :(得分:0)
select level*&n from dual connect by level<=10;
这里你可以给出你想要乘法表的任何数字。
答案 3 :(得分:0)
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