I'm imlementing attendance table report for date range:
Student 01.12 02.12 03.12 04.12 05.12 06.12
STUDENT1 TRUE TRUE TRUE FALSE TRUE FALSE
STUDENT2 TRUE FALSE TRUE TRUE TRUE TRUE
My table :
id_
student_
date_
present_
I'm imlementing attendance table report for date range:
Student 01.12 02.12 03.12 04.12 05.12 06.12
STUDENT1 TRUE TRUE TRUE FALSE TRUE FALSE
STUDENT2 TRUE FALSE TRUE TRUE TRUE TRUE
My table :
id_
student_
date_
present_
I am feeling lucky. So here is my guess at what you might be asking:
SELECT * FROM crosstab(
$$SELECT student_, date_, present_
FROM tbl
WHERE date_ BETWEEN '2015-12-01'::date AND '2015-12-06'::date
ORDER BY 1,2$$
,$$SELECT unnest('{2015-12-01, 2015-12-02, 2015-12-03
, 2015-12-04, 2015-12-05, 2015-12-06}'::date[])$$)
AS ct ("Student" text, "01.12" bool, "02.12" bool, "03.12" bool
, "04.12" bool, "05.12" bool, "06.12" bool);
Explanation: