我希望使用交叉表功能在Postgres中旋转查询。我已经创建了扩展名:tablefunc,但是我的查询无法正常工作(我已经执行了内部查询并且可以正常工作)
下面是我的查询:
select *
from crosstab
(
'select form_type, title, count(title) as total
from table_name
where timestamp >= '2019-01-01'
and title in ('this_form','that_form')
group by form_type, title
order by 1,2,3'
)
AS ct("Form_type" text, "Form" int, "Form_2" int)
内部查询的结果
form_type || title || total
A Form1 5
B Form2 9
我想使用交叉标记返回的内容:
form_type || Form1 || Form2
A 5
B 9