如何将 oracle 查询转换为 PostgreSQL 以获得 table 的计数
How to convert the the oracle query to PostgreSQL to get the count of table
我想将提到的 oracle 查询转换为 PostgreSQL 以获得 table
的计数
select count(*) from student connect by prior std_id=std_roll
Oracle 的 connect by
可以重写为标准 SQL(和 Postgres)中的递归 common table expression:
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;
然而,这并没有真正意义。以上是select count(*) from student
的复杂写法(假设std_roll
和std_id
之间有外键)
我想将提到的 oracle 查询转换为 PostgreSQL 以获得 table
的计数select count(*) from student connect by prior std_id=std_roll
Oracle 的 connect by
可以重写为标准 SQL(和 Postgres)中的递归 common table expression:
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;
然而,这并没有真正意义。以上是select count(*) from student
的复杂写法(假设std_roll
和std_id
之间有外键)