当我使用这个查询时,
select
receipt_num, trx_num,
(case when receipt_amount > 5000 then '1' else 'null') as stamp_value,receipt_amount
from ra_customer_all where receipt_amount > 5000;
它给出这样的输出:
receipt_num trx_num stamp_value receipt_amount
23679 sf35fd 1 5400
23679 sdf2424 1 5400
23679 rer434 1 5400
987444 dgd343 1 98432
7610 sdf23 1 6756
7610 dfg242 1 6756
但我希望输出看起来像这样:
receipt_num trx_num stamp_value receipt_amount
23679 sf35fd 1 5400
23679 sdf2424 null 5400
23679 rer434 null 5400
987444 dgd343 1 98432
7610 sdf23 1 6756
7610 dfg242 null 6756
对于每个收据编号 > 5000,邮票值应仅打印一次。
(*一张收据可能包含一个或多个 trx_num*)
请帮我解决一下这个。
select
acra.attribute6 office_code,
acra.attribute5 collection_number,
acra.receipt_number instrument_number,
acra.receipt_date collection_date,
acra.amount collected_amount,
ac.customer_name,
rcta.trx_number ,
(case row_number() over (partition by acra.receipt_number order by rcta.trx_number) when acra.amount > 5000 then '1' else 'NULL' end) stamp_value,
from
ar_cash_receipts_all acra,
ar_customers ac,
ra_customer_trx_all rcta,
ar_receivable_applications_all araa
where
acra.pay_from_customer=ac.customer_id and
acra.cash_receipt_id = araa.cash_receipt_id and
araa.applied_customer_trx_id=rcta.customer_trx_id
and acra.amount > 5000
好的,我更新了我的加入查询,我在其中添加了分区,但作为缺少的关键字给出了错误。有人可以编辑它以获得所需的输出