我想總結一列AMOUNT,結果是填充列BALANCE。如果列類型是DEBIT,那麼它將總和..但是如果列類型是KREDIT,那麼它將是負的。這是表table image基於另一列的總和列laravel
創建該表中,我使用這個查詢中laravel控制器:
$get_result = DB::select(DB::raw("SELECT statement.created_at, statement.descript, statement.amount, statement.sign, statement.reference
FROM statement,lender
WHERE statement.created_at BETWEEN DATE_ADD(' $date_from ',INTERVAL 1 DAY)
AND '$date_to'
AND statement.lender_id = lender.id
AND lender.user_id= $userId "));
和我用鑑於此代碼來顯示數據:
<thead>
<tr class="txtcenter">
<th class="all">Date </th>
<th class="all">Description </th>
<th class="all">Amount</th>
<th class="all">Type</th>
<th class="all">Reference</th>
<th class="all">Balance</th>
</tr>
</thead>
<tbody>@foreach($get_result as $statement)
<tr class="accordion">
<td>{{SUBSTR($statement->created_at,0,10) }}</div>
<td>{{$statement->descript}} </div>
<td>IDR {{number_format($statement->amount, 0, '.', ',')}} </div>
<td>{{ $statement->sign }} </div>
<td>{{ $statement->reference }} </div>
<td> </div>
</tr>@endforeach
</tbody>
我不知道如何使適當的代碼來計算這一切。 請幫幫我。 在此先感謝
你的意思是替換上面的查詢嗎?得到這個錯誤:#1064 - 你的SQL語法有錯誤;檢查與您的MariaDB服務器版本相對應的手冊,以便在'descript ='Credit'then statement.amount else 0 end'附近使用正確的語法 - (sum(case when line =「Deb'at line 2 – arbong
what is the數據庫字段名稱您在哪裏存儲了「借方」/「貸方」值? –
數據庫字段名稱其中存儲了「借方」/「貸方」值是描述 – arbong