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.
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community