How to do an inner join on row number in sql server

前端 未结 2 593
终归单人心
终归单人心 2020-11-29 09:02

SQL Server 2008

Two tables:

Table A has following data:

RowA
RowB
RowC
RowD

Table B has following data:

Row         


        
相关标签:
2条回答
  • 2020-11-29 09:42
    select A.sectionname, A.Basicprice,A.Brand,A.Description,A.Description,A.Grandtotal,A.GST,A.Gstvalue,A.Hsncode,A.Image,A.Installationcharge,A.Model,B.Age,B.Mark,B.Name,B.class
    
    from(
       SELECT Class,row_number() over (order by class) as row_num,Age,Mark,Name
       FROM classtable)B
       LEFT join
       (SELECT sectionname,row_number() over (order by sectionname) as row_num,Basicprice,Brand,Description,Grandtotal,GST,Gstvalue,Hsncode,Image,Installationcharge,Model
       FROM testtable)A
    
    on  A.row_num=B.row_num
    
    0 讨论(0)
  • 2020-11-29 10:01

    try this:

    USE ROW_NUMBER() function in sql server 2008

    select A.val,B.val 
    from(
        SELECT val,row_number() over (order by val) as row_num
        FROM A)A
    join
        (SELECT val,row_number() over (order by val) as row_num
        FROM B)B
    on  A.row_num=B.row_num
    ORDER BY A.val,B.val
    


    SQL fiddle demo

    0 讨论(0)
提交回复
热议问题