sql - 创建 Tablefun 扩展后使用“Crosstab”功能
问题描述
我希望使用交叉表函数在 Postgres 中旋转我的查询。我已经创建了扩展:tablefunc 但我的查询不起作用(我已经执行了内部查询并且它有效)
- 这是在 Pgadmin4
- 我已经使用“创建扩展表函数”创建了表函数扩展
以下是我的查询:
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
我想要使用 CROSSTAB 返回的内容:
form_type || Form1 || Form2
A 5
B 9
解决方案
推荐阅读
- sql - BigQuery - “for loop like”操作,以帮助将行批量插入到表中
- tensorflow2.0 - TensorFlow 2,如何在 C++ API 中重置有状态的 RNN 隐藏状态?
- python - FLASK PYTHON ModuleNotFoundError:没有名为“tensorflow”的模块
- nginx - Istio - 用于 Azure Front Door 的默认 ssl 证书
- python-3.x - Green to python,Discord Embed 有问题
- java - 在 firestore 中使用 orderBy 执行 whereEqualTo
- go - 子包应该有自己的 go.mod 文件吗?
- openmp - OpenMP 原子比较和交换
- javascript - 有没有办法覆盖console.log报告的文件/行信息?
- python - 使用 mysql 和 csv 文件动态插入