'Return values for latest three month

I am new to sql and I have a question for SQL using Data GRIP.

I have a table with list of client name as my rows and for each client (row) I have multiple dates. enter image description here

I need to change the structure of the table and instead of having my dates as rows, I want to list them as column but only for the latest three month AND if I do not have any value then return ' no activity'

enter image description here

I used the below sql query but the result is incorrect because I still cannot get distinct list of my rows

SELECT DISTINCT(client),

  CASE WHEN month = dateadd(month, -3, date_trunc('MONTH',getdate())::DATE)
        THEN cast(categories AS varchar(12))
           ELSE 'no activity' END AS latest_three_month,
  CASE WHEN month = dateadd(month, -2, date_trunc('MONTH',getdate())::DATE)
        THEN cast(categories AS varchar(12))
           ELSE 'no activity' END AS latest_second_month,
  CASE WHEN month = dateadd(month, -1, date_trunc('MONTH',getdate())::DATE)
        THEN cast(categories AS varchar(12))
           ELSE 'no activity' END AS latest_month
FROM MYTABLE;

Even though, I specified "SELECT DISTINCT(client)", but the result is looks like the below image and it is incorrect:

enter image description here

Appreciate your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source