sql server - self joining sql without aggregation -


i have table below structure:

    id   employeetype   name     1     contract      john, baxter     2     contract      will, smith     3     full          josh, stevens     4     full          sitar, zhang 

all need pivot below output:

      contract_employee   fulltime_employee       john, baxter        josh, stevens       will,smith          sitar, zhang 

any idea how can in 1 query?

that's kind of funny request. here's how it: (basically, deriving fake key "join" on 2 derived tables, on contractors, 1 employees)

    create table #table1         ([id] int, [employeetype] varchar(8), [name] varchar(13))     ;      insert #table1         ([id], [employeetype], [name])     values         (1, 'contract', 'john, baxter'),         (2, 'contract', 'will, smith'),         (3, 'full', 'josh, stevens'),         (4, 'full', 'sitar, zhang'),         (5, 'full','bob, bob'),         (6, 'contract','bob, bob')     ;       select     c.name contractemployee,     f.name fulltime_employee         (     select     row_number() on (order id) rn,     name         #table1          employeetype = 'contract'       ) c     full join (     select     row_number() on (order id) rn,     name         #table1          employeetype = 'full'     ) f     on  c.name = f.name or c.rn = f.rn 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -