我有一個這樣的表。ORACLE - 自定義ORDER BY來訂購數據行對
|DATE |VOUCHER_NO|CURRENCY|AMOUNT|DESCRIPTION|JOURNAL_TYPE|COA_NO |
|03/30/2016|0000000001|USD |2000 |ABCD |CREDIT |150001 |
|03/30/2016|0000000001|USD |2000 |ABCD |DEBIT |150001 |
|03/30/2016|0000000002|USD |1500 |ABCD |CREDIT |150002 |
|03/30/2016|0000000002|USD |1000 |ABCD |DEBIT |150002 |
|03/30/2016|0000000002|USD |500 |ABCD |DEBIT |150002 |
|03/30/2016|0000000003|USD |4000 |ABCD |CREDIT |150003 |
|03/30/2016|0000000003|USD |2000 |ABCD |DEBIT |150003 |
|03/30/2016|0000000003|USD |1000 |ABCD |DEBIT |150003 |
|03/30/2016|0000000003|USD |500 |ABCD |DEBIT |150003 |
|03/30/2016|0000000003|USD |500 |ABCD |DEBIT |150003 |
我必須按最大金額排序表,首先使用日記帳類型信用。並且它必須跟隨以Voucher_No爲基礎的借記(不涉及借方的金額),然後是第二大金額,如此。
|DATE |VOUCHER_NO|CURRENCY|AMOUNT|DESCRIPTION|JOURNAL_TYPE|COA_NO |
|03/30/2016|0000000003|USD |4000 |ABCD |CREDIT |150003 |
|03/30/2016|0000000003|USD |2000 |ABCD |DEBIT |150003 |
|03/30/2016|0000000003|USD |1000 |ABCD |DEBIT |150003 |
|03/30/2016|0000000003|USD |500 |ABCD |DEBIT |150003 |
|03/30/2016|0000000003|USD |500 |ABCD |DEBIT |150003 |
|03/30/2016|0000000001|USD |2000 |ABCD |CREDIT |150001 |
|03/30/2016|0000000001|USD |2000 |ABCD |DEBIT |150001 |
|03/30/2016|0000000002|USD |1500 |ABCD |CREDIT |150002 |
|03/30/2016|0000000002|USD |1000 |ABCD |DEBIT |150002 |
|03/30/2016|0000000002|USD |500 |ABCD |DEBIT |150002 |
如何做到這一點?如果我先按金額訂購,則借記卡將分散至下方,如果我先按voucher_no訂購,則不會按金額排序。
這是否會在'debit'之前爲特定優惠券排序'credit'? –
@sql_dummy:如果您首先需要「credit」,則必須添加另一列,然後編輯我的答案。 – dnoeth
他用最大的金額要求代金券。他詢問信用量最大的代金券。 –