使用此查询,我得到以下结果:-
$date = $row['date'];
$t_fee = mysql_query("SELECT sum(labs.test_fee), sum(labs.discount), sum(labs.received) from labs join patients on labs.p_id = patients.p_id where date = '$date'");
while($row = mysql_fetch_array($t_fee)) {
$fee_sum = $row[0];
$discount_sum = $row[1];
$received = $row[2];
$after_discount = $fee_sum - $discount_sum;
$balance = $after_discount - $received;
-----------------------------
Date | Total Revenue |
-----------------------------
2017-05-23 | 1,000 |
2017-05-19 | 4,190 |
2017-05-19 | 4,190 |
2017-05-19 | 4,190 |
2017-05-18 | 1,350 |
2017-05-08 | 690 |
2017-05-02 | 2,280 |
-----------------------------
Grand Total | 9,510 |
-----------------------------
我想得到这样的结果:-
-----------------------------
Date | Total Revenue |
-----------------------------
2017-05-23 | 1,000 |
2017-05-19 | 4,190 |
2017-05-18 | 1,350 |
2017-05-08 | 690 |
2017-05-02 | 2,280 |
-----------------------------
Grand Total | 9,510 |
-----------------------------
最佳答案
where date = '$date'
group by date;
您需要按日期分组,因此在查询中附加
group by date;
。关于php - 我需要从表中获取Date Wise总计,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44175127/