如果我把它放在一个查询文件中,pg promise将如何处理它?</ p>
WITH regional_sales AS (
SELECT region, SUM(amount) AS total_sales
FROM orders
GROUP BY region
), top_regions AS (
SELECT region
FROM regional_sales
WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
)
SELECT region,
product,
SUM(quantity) AS product_units,
SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product;
是否需要使用WITH?我想有以下用例,
SELECT * FROM balance WHERE bank_id = 1 FOR UPDATE
(强制所有银行ID 1记录被锁定)
SELECT * FROM balance WHERE bank_id = 1 AND amount = 500
(只获取银行ID为1的行,但仍确保所有银行ID记录1都被锁定。