How to query results from temp tables in typeorm

Viewed 153

My query is something like this and it has two temp tables. I need to implement this in typeorm query builder.

 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;

My approach was to write queries separately and join them programatically. Is there any way to do this with typeorm query builder?

0 Answers
Related