Weather Observation Station 5

  • + 1 comment

    select CASE when occupation='Doctor' then CONCAT(name,'(D)') when occupation='Professor' then CONCAT(name,'(P)') when occupation='Singer' then CONCAT(name,'(S)') else CONCAT(name,'(A)') end as occ_nam from OCCUPATIONS order by name asc;

    Nice work! Your solution definitely gets the job done. The only challenge with this approach is that it hard-codes the occupations, so if a new one gets added later, the query would need to be updated manually. Using something like LEFT(occupation,1) (or SUBSTR depending on the SQL flavor) can make it more flexible and maintainable since it automatically works for any occupation. But overall, this is a solid way to solve it with CASE!