Dengan asumsi saya memahami permintaan Anda dengan benar, saya pikir apa yang Anda butuhkan adalah sesuatu seperti ini:
SELECT "periods"."start_date",
"periods"."end_date",
SUM(CASE WHEN "balance_transactions"."created" BETWEEN "periods"."start_date" AND "periods"."end_date" THEN "balance_transactions"."fee" ELSE 0.00 END) AS period_sum
FROM "balance_transactions"
JOIN charges ON balance_transactions.source = charges.balance_id
JOIN ( SELECT '2013-12-20'::date as start_date, '2014-01-19'::date as end_date UNION ALL
SELECT '2013-12-21'::date as start_date, '2014-01-20'::date as end_date UNION ALL
SELECT '2013-12-22'::date as start_date, '2014-01-21'::date as end_date UNION ALL
SELECT '2013-12-23'::date as start_date, '2014-01-22'::date as end_date UNION ALL
SELECT '2013-12-24'::date as start_date, '2014-01-23'::date as end_date
) as periods
ON "balance_transactions"."created" BETWEEN "periods"."start_date" AND "periods"."end_date"
WHERE "balance_transactions"."account_id" = 6
AND "balance_transactions"."type" = 'charge'
AND "charges"."refunded" = false
AND "charges"."invoice" IS NOT NULL
GROUP BY "periods"."start_date", "periods"."end_date"
Ini akan mengembalikan Anda semua periode yang Anda minati dalam satu kumpulan hasil tunggal. Karena kueri 'dihasilkan' dengan cepat di front-end Anda, Anda dapat menambahkan sebanyak mungkin baris ke bagian periode yang Anda inginkan.
Sunting:dengan beberapa percobaan dan kesalahan, saya berhasil membuatnya bekerja [di sqlFiddle][1] dan memperbarui sintaks di atas.