how to use case statements efficiently

42 Views Asked by At

I have repetitive and hardcoded query like this. Following is just a tip of the iceberg. there are multiple similar statements (not shown below).Is there a way to make it short?

Create table analysis as
Select name,
case when gender = 'M'  then A  else ' ' end) as MA,
case when gender = 'M'  then B  else . end) as MB,
case when gender = 'M'  then C  else . end) as MC,
case when gender = 'F'  then A  else ' ' end) as FA,
case when gender = 'F'  then B  else . end) as FB,
case when gender = 'F'  then C  else . end) as FC
FROM student;
0

There are 0 best solutions below