Sort by

recency

|

2171 Discussions

|

  • + 0 comments

    Finally figured out

    SELECT COALESCE(MAX(Doctor), 'NULL') AS Doctor, COALESCE(MAX(Professor), 'NULL') AS Professor, COALESCE(MAX(Singer), 'NULL') AS Singer, COALESCE(MAX(Actor), 'NULL') AS Actor FROM ( SELECT CASE WHEN Occupation = 'Doctor' THEN Name END AS Doctor, CASE WHEN Occupation = 'Professor' THEN Name END AS Professor, CASE WHEN Occupation = 'Singer' THEN Name END AS Singer, CASE WHEN Occupation = 'Actor' THEN Name END AS Actor, ROW_NUMBER() OVER (PARTITION BY Occupation ORDER BY Name) AS rn FROM OCCUPATIONS ) AS temp GROUP BY rn ORDER BY rn;

  • + 0 comments

    wow, this was really tuf uwu :3

    with cte as (
        select name, occupation, row_number() over(partition by occupation order by name) as rn 
        from occupations
    )
    select
        max(case when occupation = 'Doctor' then name end) as Doctor,
        max(case when occupation = 'Professor' then name end) as Professor,
        max(case when occupation = 'Singer' then name end) as Singer,
        max(case when occupation = 'Actor' then name end) as Actor
    
    from cte
    group by rn;
    
  • + 0 comments

    Oracle option

    select max(CASE WHEN occupation = 'Doctor' THEN name END) Doctor, max(CASE WHEN occupation = 'Professor' THEN name END) Professor, max(CASE WHEN occupation = 'Singer' THEN name END) Singer, max(CASE WHEN occupation = 'Actor' THEN name END) Actor from (select name, occupation, row_number() over (partition by occupation order by name asc) rn from occupations ) group by rn order by rn asc ;

  • + 0 comments

    select Name||'('||substr(occupation,1,1)||')' as output from occupations union all select 'There are a total of' || count(*) ||' '||occupation||'s.' as output from occupations group by occupation order by output;

  • + 0 comments

    MS SQL SERVER

    WITH ordered AS ( SELECT Name, Occupation, ROW_NUMBER() OVER(PARTITION BY Occupation ORDER BY Name) AS rn FROM OCCUPATIONS ), ctc as ( SELECT * FROM ( SELECT Name, Occupation, rn FROM ordered ) AS src PIVOT ( MAX(Name) FOR Occupation IN ([Doctor], [Professor], [Singer], [Actor]) ) AS p ) SELECT Doctor, Professor, Singer, Actor FROM ctc ORDER BY rn;