Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 06:00 PM
@ELENI GEORGOUSI : Can you try using a common table expression (CTE) something like below?
WITH cte_total_qty AS (
SELECT SUM(qty) AS total_qty
FROM my_schema.my_staging_source_table
WHERE YEAR(ModifiedDate) = ${var.year_variable} AND CostCenter = $CostCenter
)
Select col1, col2,...
from....Note that the CTE is executed only once, before the main SQL statement, and the result is reused for each row in the main SQL statement. Hope this helps!