0
我使用此查询得到以下结果得到日期智者总: -我需要从表
$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“' – Mohammad
or select distinct(date).... where date ='$ date' –
您必须使用mysqli扩展而不是mysql,因为这样如果用户输入'$ date',你应该使用PDO或准备好的语句来避免sql注入。 – Mohammad