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_codetxn_daytxn_cnttotal_amountavg_amount
CARD2024-04-0128000.004000.00
CARD2024-04-02218500.009250.00
CARD2024-04-03210200.005100.00
Gazprombank

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid