【发布时间】:2020-05-13 09:28:20
【问题描述】:
CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_DupAuditCriteria_1`()
BEGIN
set @RowNbr=concat(date_format(curdate(),'%Y%m%d'),'0000000');
select temp.* from
(SELECT c.*, concat(c.VendorID,a.VendorID) as MergeH200A, concat(a.VendorID,c.VendorID) as MergeH200B, 'New' as Record_Type, @RowNbr:= @RowNbr + 1 AS ClaimID
FROM tbldupaudit_currentitems AS c
inner join tbldupaudit_archiveitems a
on c.InvoiceID = a.InvoiceID
and c.GrossAmount = a.GrossAmount) as temp
inner join tbldupaudit_archiveitems b
on temp.InvoiceID = b.InvoiceID
and temp.GrossAmount = b.GrossAmount
and temp.VendorID = b.VendorID
and temp.VoucherID <> b.VoucherID
Union all
select temp1.* from
(SELECT f.*, concat(f.VendorID,d.VendorID) as MergeH200A, concat(d.VendorID,f.VendorID) as MergeH200B, 'ARCHIVE' as Record_Type, 1 AS ClaimID
FROM tbldupaudit_archiveitems AS f
inner join tbldupaudit_currentitems d
on f.InvoiceID = d.InvoiceID
and f.GrossAmount = d.GrossAmount) as temp1
inner join tbldupaudit_currentitems e
on temp1.InvoiceID = e.InvoiceID
and temp1.GrossAmount = e.GrossAmount
and temp1.VendorID = e.VendorID
and temp1.VoucherID <> e.VoucherID
order by InvoiceID, Record_Type DESC;
END
尝试为每对创建唯一的 ClaimID。我能够为前半联合所有生成序列号,但相同的 ClaimID 不能在另一半联合全部生成。 请帮助我了解如何为匹配的项目创建/生成一个唯一 ID。
谢谢!]1
【问题讨论】:
-
尝试为每对创建唯一的 ClaimID。 什么PAIR? 匹配项什么是匹配标准?
-
What PAIR: Current items vs Archive items,逻辑在当前和存档表中识别匹配的项目。现在我需要通过创建一个唯一 ID 来告诉用户它们是一对的。
-
逻辑识别匹配项什么逻辑?什么表达式(在数据集上唯一)标识记录并允许设置记录对匹配?
-
'''标准相同InvoiceID和相同量的输入表CurrentItems ArchiveItems InvoiceID InvoiceID InvoiceID金额12345 3000 12345 3000 54321 4560 123456 2000 12345 3000 12345678 4000结果是这样ClaimID的InvoiceID InvoiceID UNQ12345 12345 3000 UNQ12345 12345 3000 ''' 这个 ClaimID 对于每个 PAIR 都应该是唯一的。如果我不了解 MySQL 和数据库世界,我很抱歉。
-
请将事实添加到问题文本中,而不是添加到 cmets 中。格式正确。
标签: mysql parameter-passing union union-all