我想将提到的 oracle 查询转换为 PostgreSQL 以获取表的计数
select count(*) from student connect by prior std_id=std_roll
我想将提到的 oracle 查询转换为 PostgreSQL 以获取表的计数
select count(*) from student connect by prior std_id=std_roll
Oracleconnect by
可以重写为标准 SQL(和 Postgres)中的递归公用表表达式:
with recursive tree as (
select std_id, std_roll
from student
where std_roll is null --<< I assume you are missing a START WITH in Oracle
union all
select c.std_id, c.std_roll
from student c
join tree p on p.std_id = c.std_roll
)
select count(*)
from tree;
然而,这并没有真正的意义。以上是一种复杂的写法(假设andselect count(*) from student
之间有外键)std_roll
std_id