检索所有相关调整详细信息的最新发票记录
我正在尝试检索具有所有相关调整详细信息的最新发票记录(表可能包含重复的发票)。 不幸的是,以下SQL只能检索单个记录。 (例如,如果特定最新发票具有多个充电代码,它将仅检索1)
选择A.invoice,A.Shipment_nbr,A.Invoice_date,b.adjust_rsn,b.adjust_date,c.charge_code,c.charge_code,c.charge_amt 从开票a 内部加入调整B 在A.Shipment_nbr上= B.Shipment_nbr 内联电荷c 在b.uniq_id上= c.uniq_id 其中'05 -01-2022'和'05 -31-2022'之间的b.adjust_date 合格row_number() A.Shipment_nbr A.invoice_date desc)= 1 = 1
参考表上的图像,当前结果和预期结果。 表格,当前结果&预期结果
I'm trying to retrieve the latest invoice record (table may contains duplicate invoices) with all relevant adjustment details.
Unfortunately, the below SQL only able to retrieve a single line of record. (e.g. if the particular latest invoice has multiple charge code, it will only retrieve 1 of it)
SELECT a.Invoice, a.Shipment_Nbr, a.Invoice_date, b.Adjust_rsn, b.Adjust_date, c.Charge_code, c.Charge_Amt
FROM Invoicing a
Inner Join Adjust b
on a.Shipment_Nbr=b.Shipment_Nbr
Inner Join Charge c
on b.uniq_id=c.uniq_id
WHERE b.Adjust_date between '05-01-2022' and '05-31-2022'
QUALIFY ROW_NUMBER () OVER (PARTITION BY
a.Shipment_Nbr
ORDER BY a.Invoice_date DESC) = 1
Refer to the image on the tables, current result and the expected result.
Tables, Current Result & Expected Result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能应该这样做
This should probably do it