SELECT tbla.ID, tbla.Items, tblb.ItemId, tblb.volume
FROM (
SELECT ID, Items, row_number() over( order by ID desc )row_numA
FROM TableA
)tbla
INNER join
( SELECT ItemId,volume,row_number() over(order by ItemId desc)row_numB
FROM TableB
) tblb ON tbla.row_numA=tblb.row_numB
order by tbla.ID asc;
2条答案
按热度按时间hpcdzsge1#
如果有两个表的行数完全相同,但没有其他明显的关系,并且在这两个表上,ID和itemID分别定义了行的唯一性,则可以对row_number应用MySQL ROW_NUMBER Function和join,order by子句很重要。
请尝试:
https://dbfiddle.uk/?rdbms=mariadb_10.6&fiddle=15d13d29a84a55c4d029115c87eebe8f
pu82cl6c2#
试试这个