如何将 CTE 转换为嵌套 SELECT

how to convert CTE to nested SELECT

我有下面发布的查询。我想使用嵌套的 SELECT 语句而不是 CTE。我想让外部 SELECT 语句说明 table grid_cell_data 中包含的列 我不想使用 j.* 我想改用列名

查询:

WITH j AS (
 SELECT
   ST_AsMVTGeom(
     st_geomfromtext(geometryofcellrepresentativetobuffer),
     ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096,4096)))
 FROM grid_cell_data where id = 3
)
SELECT ST_AsMVT(j.*) FROM j

grid_cell_data table

CREATE TABLE IF NOT EXISTS grid_cell_data (
   id SERIAL PRIMARY KEY,
   isTreatment boolean,
   isBuffer boolean,
   geometryOfCellRepresentativeToTreatment geometry,
   geometryOfCellRepresentativeToBuffer geometry 
)

您只需要 select 在 CTE/Subquery 中需要的所有记录,在外部查询中您可以继续使用 jj.*。如果您需要进一步 select 特定列,请将它们放在 SELECT 中的括号之间,以便它代表 ST_AsMVT 的记录,例如

WITH j AS (
 SELECT *,
   ST_AsMVTGeom(
     st_geomfromtext(geometryofcellrepresentativetobuffer),
     ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096,4096))) AS mvt_geom
 FROM grid_cell_data where id = 3
)
SELECT ST_AsMVT((id,isTreatment,isBuffer,mvt_geom)) 
FROM j