Question: The function `pydoc.doc()` returns `None`, but i would like to capture the output the function prints, how can i do that using python code?

Answer: 
You could use the CASE expressions like below.

```
SELECT student_id,
   ISNULL(MAX(CASE WHEN DAY = 'Monday'
              THEN 'Y'
              END),'N') AS 'M',
   ISNULL(MAX(CASE WHEN DAY = 'Tuesday'
        THEN 'Y'
        END),'N') AS 'T',
   ISNULL(MAX(CASE WHEN DAY = 'Wednesday'
        THEN 'Y'
        END),'N') AS 'W',
   ISNULL(MAX(CASE WHEN DAY = 'Thursday'
        THEN 'Y'
        END),'N') AS 'T',
   ISNULL(MAX(CASE WHEN DAY = 'Friday'
        THEN 'Y'
        END),'N') AS 'F',
   CONCAT(Start_time,'-',end_time) as Time,
   Location
   FROM student
   GROUP BY student_id,CONCAT(Start_time,'-',end_time),Location

```

Result set based on your sample data

```
student_id  M   T   W   T   F   Time                Location
 x          Y   Y   N   N   N   14:00:00-16:00:00   Class Room x
 x          N   N   N   Y   N   16:00:00-17:00:00   Class Room x

```
I think you want conditional aggregation:

```
select student_id, time, location,
       max(case when day = 'Monday' then 'Y' else 'N' end) as mon,
       max(case when day = 'Tuesday' then 'Y' else 'N' end) as tue,
       . . .
from t
group by student_id, time, location;

```

Because you are using Postgres, I would advise you to use booleans rather than characters for each day. That results in the simpler:

```
select student_id, time, location,
       bool_or(day = 'Monday') as mon,
       bool_or(day = 'Tuesday') as tue,
       . . .
from t
group by student_id, time, location;

```