Anant Infomedia Interview Question

Write query (group by ). Draw pattern.