如下两张表,G0516A和G0516B
要求G0516B按顺序与G0516A的第一个WEEK1依次有序的组合,直到依次组合完毕,预计结果如下:
测试数据:
`
CREATE TABLE G0516A
(
WEEKS VARCHAR(10)
)
INSERT INTO G0516A VALUES
(‘WEEK1’),(‘WEEK2’),(‘WEEK3’),
(‘WEEK4’),(‘WEEK5’),(‘WEEK6’),
(‘WEEK7’),(‘WEEK8’),(‘WEEK9’),
(‘WEEK10’)
CREATE TABLE G0516B
(
TEAMS VARCHAR(10)
)
INSERT INTO G0516B VALUES
(‘TEAM1’),(‘TEAM2’),(‘TEAM3’)`
答案:
select weeks,teams
from (
select *,row_number(),over(order by @@rowcount from G0516A) a
left join(
select *,row_number() over (order by @@rowcount from G0526B)b
on a.AID%3=b.BID%3