/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/sql/sql-8821-007/main.sql
35 строк
1 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
-- Оптимизация запроса к таблице фактов продаж SELECT /*+ PARALLEL(sales_facts 8) PARALLEL(time_dim 2) PARALLEL(product_dim 2) PARALLEL(customer_dim 2) STAR FACT(sales_facts) DIMENSION(time_dim product_dim customer_dim) */ td.fiscal_year, td.fiscal_quarter, pd.product_category, pd.product_subcategory, cd.customer_region, cd.customer_segment, COUNT(sf.sale_id) AS transaction_count, SUM(sf.quantity) AS total_quantity, SUM(sf.sales_amount) AS total_sales, AVG(sf.sales_amount) AS avg_transaction_value FROM sales_facts sf JOIN time_dimension td ON sf.time_id = td.time_id JOIN product_dimension pd ON sf.product_id = pd.product_id JOIN customer_dimension cd ON sf.customer_id = cd.customer_id WHERE td.fiscal_year = 2025 AND cd.customer_region IN ('North America', 'Europe') GROUP BY td.fiscal_year, td.fiscal_quarter, pd.product_category, pd.product_subcategory, cd.customer_region, cd.customer_segment HAVING SUM(sf.sales_amount) > 1000000 ORDER BY total_sales DESC;