我有数据库字段bill_amount
,paid_amount
,due_amount
..如果客户是使用bill_amount
创建的,paid_amount
& due_amount
&像240,200& 40.并且第二天他清算了金额,即,paid_amount变为240& due_amount变为0。
如果我试图得到每日收集的报告,这是每日paid_amount,其中yesteday paid_amount不应该添加.means今天的收集应该是40而不是240 ..如何在sql中跟踪它?
以下sql查询今天返回今天的paid_amount总和,但它还包括昨天的金额..如何排除同一客户的昨天paid_amount
?
$daily_collection_m = DB::select("SELECT sum(transactions.paid_amount) as daily_collection_m FROM transactions
WHERE CAST(transactions.created_at as DATE) ='$day' ;