Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

dflow said:

I want to combine the 2 and get trader count and deposit_amount sum per day

Sum per day for what? Total deposits of all transactions? Sum of deposits made by a single trader? Grouping by created_at makes no sense. Seems like you should group by the trader_id. This will make every sigle trader have his very own row in the result. Your whereBetween looks good. Just select the trader_id, SUM(deposit_amount) as TotalDeposits and COUNT(*) as DepositCount.

Last updated 1 year ago.
0

Firtzberg said:

dflow said:

I want to combine the 2 and get trader count and deposit_amount sum per day

Sum per day for what? Total deposits of all transactions? Sum of deposits made by a single trader? Grouping by created_at makes no sense. Seems like you should group by the trader_id. This will make every sigle trader have his very own row in the result. Your whereBetween looks good. Just select the trader_id, SUM(deposit_amount) as TotalDeposits and COUNT(*) as DepositCount.

thanks for the reply.

let me clarify I would like to have a result in rows showing the summary BY DAY and count the number of unique traders per day and sum all the deposit_amounts per day.

Last updated 1 year ago.
0

I hope I understand.
Timestamps made by eloquent are of type datetime. If you group by created_at, every entry will have a row in the result. You have to convert the column (inside your SQL) to type date using DATE().
To select the number of different traders per each day, use COUNT(DISTINCT).
Use SUM to sum the deposit_amouts

SELECT DATE(created_at) AS date,
COUNT(DISTINCT trader_id) AS trader_count,
SUM(deposit_amount) AS TotalDeposits
FROM earings
WHERE created_at BETWEEN ... AND ...
GROUP BY DATE(created_at)

I think you will figure out how to build this query it in Laravel.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dflow dflow Joined 16 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.