I am trying to create a crosstab table that will have rows = months and columns = days (ie 1, 2, 3, 4...31).
Month | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 ...
------+------+------+-----+-----+-----+-----+-----+-----+-----+-----+------+------
9 | 1000 | 1500 | | | | | 500 | | | | 1500 | 2000
8 | 1000 | | | | | | | | | | |
My query is as follows:
SELECT * FROM crosstab(
$$
SELECT
extract(month from created_at) AS themonth,
extract(day from created_at) AS theday,
COUNT(*)
FROM public.users
WHERE created_at >= Now() - Interval '90 Days' AND created_at < Now() - Interval '1 days'
GROUP BY created_at
ORDER BY 1,2
$$
) AS final_result (
themonth int,
theday int
)
The below receives an error: rowid datatype does not match return rowid datatype
This is my first time using crosstab.
I have a feeling this is a simple fix and would appreciate any help. Thanks!