CREATE TABLE #yt ([name] varchar(255), [occupation] varch...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Materials Modeling Meta

Q&A for materials modelers and data scientists

CREATE TABLE #yt
([name] varchar(255), [occupation] varchar(255))
;
    
INSERT INTO #yt
    ([name], [occupation])
VALUES
     ('Sam', 'doctor'), ('julia', 'actor'), ('maria', 'singer'), ('john', 'professor'), ('Kitty', 'professor'), ('Jane', 'actor'), ('jenny', 'doctor'), ('priya', 'doctor'), ('max', 'singer'), ('joe', 'doctor')
;

-- SELECT * from #yt;


select *
from 
(
  select name, occupation
  from #yt
) src
pivot
(
  max(name)
  for occupation in (['doctor'], ['actor'], ['singer'], ['professor'])
) piv;

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results