I am trying to sort MySQL result from qry_ledger_all_balance and it's working fine, but the problem is I can only sort by PaymentDate.
I want to sort in the order of:
PaymentDatevalueDebitvalueCreditvalue
I am unable to do that. I don't know what I am doing wrong. Here is my Table Structure Sample.
+-----------------+-------+--------+---------------------+----------------------------+
| PaymentCode | Debit | Credit | PaymentDate | Particular |
+-----------------+-------+--------+---------------------+----------------------------+
| CTM-41700000008 | 25000 | 0 | 2017-05-15 17:27:28 | Token Money From Customer1 |
| CTM-41700000007 | 12000 | 0 | 2017-05-15 17:26:26 | Token Money From Customer2 |
| CRV-11700000166 | 15000 | 0 | 2016-05-15 17:57:01 | Customer1 Receipt Vourcher |
| EPV-21700000012 | 0 | 150 | 2017-05-15 14:23:26 | Cash Outflow |
| EPV-21700000004 | 0 | 1110 | 2017-05-15 14:06:48 | Cash Outflow |
| EAS-41700000001 | 0 | 10000 | 2017-05-15 12:27:47 | Employee Advance Salary |
+-----------------+-------+--------+---------------------+----------------------------+
Here is my query code in PHP
$branch_sql = "SELECT a.PaymentCode, a.Particular, a.Credit, a.Debit,
Date(a.PaymentDate) AS PaymentDate, a.BranchID, a.CCode As RefPrint,
a.RunningBalance, a.OpeningBalance, b.branchname FROM qry_ledger_all_balance AS a
INNER JOIN tblbranches AS b
ON a.BranchID = b.branchid
WHERE DATE_FORMAT(a.PaymentDate, '%Y-%m-%d') >= '$Start_Date' AND
DATE_FORMAT(a.PaymentDate, '%Y-%m-%d') <= '$End_Date'
ORDER BY a.PaymentDate ASC, a.Debit ASC, a.Credit ASC";
order by date(a.paymentdate), ...debitsof that date then allcreditsof that date