Finance
If you work finance, it's crucial to keep track of metrics to stay on top of business health. Let's take a look at some popular metrics to track and sample SQL queries:
Revenue over a period
Total revenue over a period of time
SELECT SUM(revenue)
FROM sales
WHERE date >= '2022-01-01' AND date <= '2022-12-31';
Expenses over a period
Total expenses over a period of time
SELECT SUM(expenses)
FROM expenses
WHERE date >= '2022-01-01' AND date <= '2022-12-31';
Gross profit margin over a period
SELECT (SUM(revenue) - SUM(cost)) / SUM(revenue) * 100 AS gross_profit_margin
FROM sales
WHERE date >= '2022-01-01' AND date <= '2022-12-31';
Total assets
SELECT SUM(value) AS total_assets
FROM assets;
Total liabilities
SELECT SUM(value) AS total_liabilities
FROM liabilities;
Debt to equity ratio
SELECT SUM(value) / (SELECT SUM(value) FROM equity) AS debt_to_equity_ratio
FROM liabilities;
Return on investment (ROI)
SELECT (SUM(revenue) - SUM(cost)) / SUM(cost) * 100 AS ROI
FROM sales
WHERE date >= '2022-01-01' AND date <= '2022-12-31';
Top customers by revenue
SELECT customer_name, SUM(revenue) AS total_revenue
FROM sales
GROUP BY customer_name
ORDER BY total_revenue DESC
LIMIT 10;
Top products by revenue
SELECT product_name, (SUM(revenue) - SUM(cost)) / SUM(revenue) * 100 AS profit_margin
FROM sales
GROUP BY product_name
ORDER BY profit_margin DESC
LIMIT 10;
Last updated