Как посчитать working capital в SQL
Содержание:
Зачем working capital
Working capital = деньги, доступные для операционных нужд. Если она отрицательная, компания не может оплатить short-term обязательства, идёт к insolvency. Главный liquidity indicator. Для SaaS обычно работает с large deferred revenue → working capital может быть отрицательным «здоровым» способом.
Формула
working_capital = current_assets − current_liabilitiescurrent = realizable within 12 months.
Includes:
- Cash + cash equivalents
- AR (accounts receivable)
- Inventory
- Prepaid expenses −
- AP (accounts payable)
- Accrued liabilities
- Current portion of long-term debt
- Deferred revenue (within 12 mo)
Working capital в SQL
WITH balance AS (
SELECT
SUM(CASE WHEN account_category = 'cash' THEN balance END) AS cash,
SUM(CASE WHEN account_category = 'accounts_receivable' THEN balance END) AS ar,
SUM(CASE WHEN account_category = 'inventory' THEN balance END) AS inventory,
SUM(CASE WHEN account_category = 'prepaid' THEN balance END) AS prepaid,
SUM(CASE WHEN account_category = 'accounts_payable' THEN balance END) AS ap,
SUM(CASE WHEN account_category = 'accrued_liabilities' THEN balance END) AS accrued,
SUM(CASE WHEN account_category = 'short_term_debt' THEN balance END) AS short_term_debt,
SUM(CASE WHEN account_category = 'deferred_revenue_current' THEN balance END) AS deferred_rev
FROM general_ledger
WHERE as_of_date = CURRENT_DATE
)
SELECT
COALESCE(cash, 0) + COALESCE(ar, 0) + COALESCE(inventory, 0) + COALESCE(prepaid, 0) AS current_assets,
COALESCE(ap, 0) + COALESCE(accrued, 0) + COALESCE(short_term_debt, 0) + COALESCE(deferred_rev, 0) AS current_liabilities,
(COALESCE(cash, 0) + COALESCE(ar, 0) + COALESCE(inventory, 0) + COALESCE(prepaid, 0))
- (COALESCE(ap, 0) + COALESCE(accrued, 0) + COALESCE(short_term_debt, 0) + COALESCE(deferred_rev, 0)) AS working_capital
FROM balance;Положительный — здоровая liquidity. Отрицательный — флаг (исключение SaaS с deferred rev).
Current ratio
current_ratio = current_assets / current_liabilitiesSELECT
current_assets / NULLIF(current_liabilities, 0) AS current_ratio,
CASE
WHEN current_assets / current_liabilities >= 2 THEN 'healthy'
WHEN current_assets / current_liabilities >= 1.5 THEN 'ok'
WHEN current_assets / current_liabilities >= 1 THEN 'tight'
ELSE 'critical'
END AS verdict
FROM working_capital_summary;1.5-2 — здорово. Меньше 1 — short-term obligations превышают current assets.
Динамика
SELECT
DATE_TRUNC('month', as_of_date)::DATE AS month,
SUM(CASE WHEN account_category IN ('cash', 'accounts_receivable', 'inventory', 'prepaid') THEN balance ELSE 0 END) AS current_assets,
SUM(CASE WHEN account_category IN ('accounts_payable', 'accrued_liabilities', 'short_term_debt', 'deferred_revenue_current') THEN balance ELSE 0 END) AS current_liabilities,
SUM(CASE WHEN account_category IN ('cash', 'accounts_receivable', 'inventory', 'prepaid') THEN balance ELSE 0 END)
- SUM(CASE WHEN account_category IN ('accounts_payable', 'accrued_liabilities', 'short_term_debt', 'deferred_revenue_current') THEN balance ELSE 0 END) AS working_capital
FROM general_ledger
WHERE as_of_date >= CURRENT_DATE - INTERVAL '12 months'
GROUP BY DATE_TRUNC('month', as_of_date)
ORDER BY month;Частые ошибки
Ошибка 1. Включать non-current liabilities. Long-term debt не в working capital. Только current portion.
Ошибка 2. SaaS deferred revenue. Annual prepayment создаёт огромный deferred revenue. Working capital negative «здорово» для PLG SaaS — компания получила cash вперёд.
Ошибка 3. Inventory как realizable. Slow-moving inventory может не быть realizable в 12 мес. Discount или write-off.
Ошибка 4. AR без allowance. Bad debt allowance уменьшает realizable AR.
Ошибка 5. Snapshot vs average. End-of-period snapshot — easy, но не отражает intra-month volatility. Average daily для better picture.
Связанные темы
- Как посчитать DSO в SQL
- Как посчитать cash conversion cycle в SQL
- Как посчитать burn rate в SQL
- Как посчитать runway в SQL
FAQ
Working capital negative — плохо?
Зависит. SaaS с annual prepay — норма. Manufacturing — flag.
Current ratio норма?
1.5-2 для большинства. SaaS часто меньше 1 (deferred rev), но cash & runway смотрят отдельно.
Quick ratio?
(Cash + AR) / Current liabilities. Без inventory. Stricter test.
Включать deferred revenue current?
Yes, технически current liability. Но business meaning — это «полученные деньги», не «долг». Многие SaaS company exclude.
Дневной snapshot?
Daily ledger snapshot — best. Иначе end-of-period — стандарт.