File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
src/main/resources/migrations Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 11CREATE OR REPLACE FUNCTION sum_by_category(start_date DATE, end_date DATE)
2- RETURNS TABLE(category_id bigserial , total_amount DOUBLE PRECISION)
2+ RETURNS TABLE(account_id bigint, category_id bigint , total_amount DOUBLE PRECISION)
33AS $$
44BEGIN
55 RETURN QUERY
6- SELECT category.id , SUM(transaction .amount) as total_amount
7- FROM transaction
8- JOIN category ON transaction .category = category .id
9- WHERE transaction .created_at BETWEEN start_date AND end_date
10- GROUP BY category .id
11- ORDER BY total_amount DESC;
6+ SELECT t.id_account, c.id AS category_id , SUM(t .amount) AS total_amount
7+ FROM transaction t
8+ JOIN category c ON t .category = c .id
9+ WHERE t .created_at BETWEEN start_date AND end_date
10+ GROUP BY t.id_account, c .id
11+ ORDER BY t.id_account, total_amount DESC;
1212END;
1313$$
1414LANGUAGE plpgsql;
You can’t perform that action at this time.
0 commit comments