Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要帮助postgresql交叉表查询吗_Sql_Postgresql_Select_Crosstab - Fatal编程技术网

需要帮助postgresql交叉表查询吗

需要帮助postgresql交叉表查询吗,sql,postgresql,select,crosstab,Sql,Postgresql,Select,Crosstab,我有两个简单的查询,如下所示,我从PostgreSQL中获取主题作为两条记录(1列) select count(*) from root.str union all select count(*) from back.str0 返回如下内容: +===+ |103| +===+ |98 | +===+ +===+===+ |103|98 | +===+===+ 但我想要这样的东西: +===+ |103| +===+ |98 | +===+ +===+===+ |103|98 | +==

我有两个简单的查询,如下所示,我从PostgreSQL中获取主题作为两条记录(1列)

select count(*) from root.str
union all
select count(*) from back.str0
返回如下内容:

+===+
|103|
+===+
|98 |
+===+
+===+===+
|103|98 |
+===+===+
但我想要这样的东西:

+===+
|103|
+===+
|98 |
+===+
+===+===+
|103|98 |
+===+===+
我已经试过了,但是Postgres在
crosstab()
函数中出错,并说该函数不存在

select * from crosstab(
   'select count(*) from root.str
    union all
    select count(*) from back.str0'::text) as (int r,int e)
您需要安装提供
交叉表()功能的

请考虑以下相关答案,并附上说明和更多建议:

另外,@a_horse编写的…

您需要安装提供
交叉表()功能的

请考虑以下相关答案,并附上说明和更多建议:

另外,@a_horse编写的…

您需要安装提供
交叉表()功能的

请考虑以下相关答案,并附上说明和更多建议:

另外,@a_horse编写的…

您需要安装提供
交叉表()功能的

请考虑以下相关答案,并附上说明和更多建议:


还有,@a_horse写的…

我不明白为什么您需要交叉表模块:

select (select count(*) from root.str) as str_count,
       (select count(*) from back.str0) as str0_count;

我不明白您为什么需要交叉表模块:

select (select count(*) from root.str) as str_count,
       (select count(*) from back.str0) as str0_count;

我不明白您为什么需要交叉表模块:

select (select count(*) from root.str) as str_count,
       (select count(*) from back.str0) as str0_count;

我不明白您为什么需要交叉表模块:

select (select count(*) from root.str) as str_count,
       (select count(*) from back.str0) as str0_count;


您使用的是哪个版本的postgresql?@JoachimIsaksson它是9.2.1 Brothern我怀疑您没有安装
tablefunc
模块。。。?我不记得怎么做了,但我怀疑如果你搜索这个网站,会有答案的。@JoachimIsaksson谢谢你,伙计,我知道了:D
create extension tablefunc
您使用的是哪个版本的postgresql?@JoachimIsaksson它是9.2.1 Brothern我怀疑您没有安装
tablefunc
模块。。。?我不记得怎么做了,但我怀疑如果你搜索这个网站,会有答案的。@JoachimIsaksson谢谢你,伙计,我知道了:D
create extension tablefunc
您使用的是哪个版本的postgresql?@JoachimIsaksson它是9.2.1 Brothern我怀疑您没有安装
tablefunc
模块。。。?我不记得怎么做了,但我怀疑如果你搜索这个网站,会有答案的。@JoachimIsaksson谢谢你,伙计,我知道了:D
create extension tablefunc
您使用的是哪个版本的postgresql?@JoachimIsaksson它是9.2.1 Brothern我怀疑您没有安装
tablefunc
模块。。。?我不记得怎么做了,但我怀疑如果你搜索网站,会有答案。@JoachimIsaksson谢谢你,伙计,我知道了:D
create extension tablefunc
谢谢,不幸的是,交叉表函数只接受物理可用表,它找不到临时表或别名选择表(
with
)。@user2889419:CTE(
with
子句)仅在它所附加的查询范围内可见,因此它必须是传递给
crosstab()
的查询字符串的一部分。临时表在当前会话中可见,可以与
crosstab()配合使用
!谢谢,不幸的是,交叉表函数只接受物理可用表,它找不到临时或别名选择(
with
)。@user2889419:CTE(
with
子句)仅在它所附加的查询范围内可见,因此它必须是传递给
交叉表()的查询字符串的一部分
。临时表在当前会话中可见,并且可以与
交叉表()配合使用。
!谢谢,不幸的是,交叉表函数只接受物理可用表,它找不到临时表或别名选择(
with
)。@user2889419:CTE(
with
子句)仅在其附加到的查询范围内可见,因此它必须是传递给
crosstab()
的查询字符串的一部分。临时表在当前会话中可见,可以正常使用
crosstab()
!谢谢,不幸的是,交叉表函数只接受物理可用表,它找不到临时或别名选择(
with
)。@user2889419:CTE(
with
子句)仅在它所附加的查询范围内可见,因此它必须是传递给
交叉表()的查询字符串的一部分
。临时表在当前会话中可见,使用
交叉表()可以正常工作。