Daily product turnover at the bank
Daily product turnover at the bank
Gazprombank is building a daily-turnover report for its corporate products. Every operation carries a client, a product category and an amount in roubles. Roll the data up to «product + day»: count the operations, sum the turnover and compute the average operation amount. Round the average to two decimals.
In PostgreSQL the amount_rub column is typed MONEY. AVG() does not accept it at all, and SUM() returns money — carrying a currency symbol and digit separators. Cast the values to numeric (amount_rub::numeric) so that total_amount and avg_amount come back as plain numbers. In ClickHouse the column is already Decimal, so no cast is needed there.
Expected output sample
| product_code | txn_day | txn_cnt | total_amount | avg_amount |
|---|---|---|---|---|
| CARD | 2024-04-01 | 2 | 8000.00 | 4000.00 |
| CARD | 2024-04-02 | 2 | 18500.00 | 9250.00 |
| CARD | 2024-04-03 | 2 | 10200.00 | 5100.00 |
Gazprombank
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inFocus radio
Paused · SomaFM · Fluid