问题描述
我有一个棘手的情况.
表中数据如下
CustomerId Transaction Type Transaction Amount
1 Payment 100
1 payment 200
1 ReversePayment -100
1 ReversePayment -200
我有一个跨国表,交易类型为付款",逆向付款".一个客户有多个记录,其中一些记录是付款",一些记录是反向付款".
I have transnational table with transaction types being "Payment", "ReversePayment". There are multiple records for a customer with some records being Payment and some being ReversePayment.
是否可以按照以下方式对数据进行排序
Is there a way to sort data as follows
CustomerId Transaction Type Transaction Amount
1 Payment 100
1 ReversePayment -100
1 payment 200
1 ReversePayment -200
如果任何人有解决方案,请提供帮助.
If any one have a solution, please help.
推荐答案
对于此数据集,应该这样做:
For this dataset, this should do it:
order by
customerId,
abs(transaction_amount),
transaction_amount desc
这种排序并不担心交易类型,而只担心金额.具有相反值的数量关系记录的绝对值标准,然后下一个标准将正值放在第一位.
This sort does not worry about the transaction type, but only about the amounts. The criteria on the absolute value of the amount ties records that have opposite values, then the next criteria puts the positive value first.
这篇关于在Oracle中排序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!