postgresql 在一条sql语句中使用多个with

11
五月
2021

Use the key word WITH once at the top. If any of your Common Table Expressions (CTE) are recursive (rCTE) you have to add the keyword RECURSIVE at the top once also, even if not all CTEs are recursive:

WITH RECURSIVE
  cte1 AS (...)         -- can still be non-recursive
, cte2 AS (SELECT ...
           UNION ALL
           SELECT ...)  -- recursive term
, cte3 AS (...)
SELECT ... FROM cte3 WHERE ...
	with RECURSIVE local as(select sum(cast(capacity as bigint))*0.2 as reserve  from public.vpx_datastore d where d.id in ('23016','23217') 
	
	and d.name like 'ds%' and d.name not like '%HDD'),
	
shared as (select count(id)*858993459200 as reserve  from public.vpx_datastore d where d.id in ('23016','23217') 
	
	and d.name like 'Cml%')
	
select * from local
TAG

网友评论

共有访客发表了评论
请登录后再发布评论,和谐社会,请文明发言,谢谢合作! 立即登录 注册会员