HackerRank - Solve Occupations using Sql Server PIVOT command

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ต.ค. 2023
  • Occupations contain four occupation types: Doctor, Professor, Singer and Actor. The goal is to transform the data, from one data format into a different structure.
    The original data in organized in rows, representing single records.
    A pivot table command will transform this data into a new table with column that represent the occupations.
    @softwareNuggets, #softwareNuggets,

ความคิดเห็น • 4

  • @ZA8103
    @ZA8103 8 หลายเดือนก่อน

    Thanks for sharing the solution. I have one question about the second example. How does it generate more than one row since you use "min"?

    • @SoftwareNuggets
      @SoftwareNuggets  8 หลายเดือนก่อน

      So, Max(name) or Min(Name) are not used as aggregate functions, they are used as placeholders for the 'name' values in each occupation category. The PIVOT operation transforms rows into columns. In this example, we are trying to display names based on their occupations. Hope this helps.

  • @VishalMax-vv2qf
    @VishalMax-vv2qf 2 หลายเดือนก่อน

    sir can please explain brief about min in the 2 nd select

    • @SoftwareNuggets
      @SoftwareNuggets  2 หลายเดือนก่อน

      Hey @VishalMax-vv2qf, did you get the source from my github account? Is this the SQL statement you need me to explain:
      select name,
      occupation,
      row_number()
      over(partition by occupation order by occupation asc, [name] asc ) as num
      from #occupations