-1

我想将提到的 oracle 查询转换为 PostgreSQL 以获取表的计数

select count(*) from student connect by prior std_id=std_roll
4

1 回答 1

0

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_rollstd_id

于 2017-01-05T13:34:35.230 回答