-- Multi-statement SQL example for query-forge.
-- All statements except the last are executed as DDL/DML.
-- The last SELECT is returned as the command output.

CREATE TEMP TABLE active AS
  SELECT product, price, category, stock
  FROM table
  WHERE active = 1;

CREATE TEMP TABLE summary AS
  SELECT category,
         COUNT(*)        AS product_count,
         SUM(stock)      AS total_stock,
         ROUND(AVG(price), 2) AS avg_price
  FROM active
  GROUP BY category;

SELECT category, product_count, total_stock, avg_price
FROM summary
ORDER BY total_stock DESC;
