Converting rows into columns

Hi All,

Thanks in Advance!

I have following requirements in scala/query

image

Can you help me how we can achieve this in scala OR any sql/thrift query to achieve above results.

Regards,
Kunal