sql server - help required with Sql query -
i have problem , got 3 tables
table   id        employee     1         1     2         2 3         3   table b id        employee        hoursworked         hourscode 1          1                 10               basic hours 2          1                 20               holiday pay 3          2                 10               basic hours 4          2                 15               overtime  table c  id        employee         payments            paycode 1           1                 100              bonus 2           2                 150              bonus 3           2                 250              student loan   i want records out of these table in minimum lines , can have 1 line says
id        employee          hour               hourscode       payments      paycode 1          1                 10                basic hours     100           bonus      2          1                 20                holiday pay      null         null 3          2                 10                basic hours      150          bonus  4          2                 15                 overtime        250          student loan   i have spent ages trying ... dont null in 2nd line comes out 100 bonus in second line employee 1
is there way can please
with    bn         (         select  *, row_number() on (partition employee order id) rn            b         ),         cn         (         select  *, row_number() on (partition employee order id) rn            c         ) select  *    bn full join         cn on      bn.employee = cn.employee         , bn.rn = cn.rn order         coalesce(bn.employee, cn.employee), coalesce(bn.rn, cn.rn)      
Comments
Post a Comment